SlideShare uma empresa Scribd logo
1 de 15
1
A Programme Under the compumitra Series
Programming Primer:
Encapsulation and Abstraction
LAB WORK GUIDE
2
OUTLINE
 Encapsulation and Abstraction Using
VB in asp.net
Creating Example Event Handler.
Example Output an Explanation.
Home Exercise.
Summary Review.
3
Encapsulation and Abstraction
Using VB in asp.net
4
EncapsulationVB – Creating Button and Label Template
Button with 'Text' Property set
to 'Encapsulation'.
Two Labels to hold the place
for output display with 'text'
property set to NULL (blank).
• Follow Standard Website Creation Steps and set your path to
C:Learner<student-id>ProgrammingPrimerEncapsulationVB
• Now Create the Execution Event Handler as a button and output
place holders as follows.
5
EncapsulationVB –Copy and Paste Code
Go to 'Default.aspx.cs' and 'Paste' the Code in
'Button1_Click' handler.
Copy this Code
Dim emp As New Employee
emp.EmployeeID = 100
emp.Salary = 8500.35
Label1.Text = "Employee ID = " & emp.EmployeeID.ToString()
Label2.Text = "Employee Salary = " & emp.Salary.ToString()
Dim emp As New Employee
emp.EmployeeID = 100
emp.Salary = 8500.35
Label1.Text="Employee ID = " &
emp.EmployeeID.ToString()
Label2.Text="Employee Salary = " &
emp.Salary.ToString()
6
EncapsulationVB –Copy Code
Class Employee
Private _employeeID As Integer
Private _salary As Double
Public Property EmployeeID() As Integer
Set(ByVal value As Integer)
_employeeID = value
End Set
Get
Return _employeeID
End Get
End Property
Public Property Salary() As Double
Set(ByVal value As Double)
_salary = value
End Set
Get
Return _salary
End Get
End Property
End Class Copy this Code
7
EncapsulationVB –Paste Code
Run Code By
pressing 'F5'
Class Employee
Private _employeeID As Integer
Private _salary As Double
Public Property EmployeeID() As Integer
Set(ByVal value As Integer)
_employeeID = value
End Set
Get
Return _employeeID
End Get
End Property
Public Property Salary() As Double
Set(ByVal value As Double)
_salary = value
End Set
Get
Return _salary
End Get
End Property
End Class
Label1.Text = "Employee ID = " & emp.EmployeeID.ToString()
Label2.Text = "Employee Salary = " & emp.Salary.ToString()
Paste code after the End
of '_Default' class
8
Employee emp = new Employee();
emp.EmployeeID = 100;
emp.Salary = 8500.30;
Label1.Text = emp.EmployeeID.ToString();
Label2.Text = emp.Salary.ToString();
EncapsulationVB –Output
Output after executing the
handler using the button.
This 'output' is generated, because we
are trying to fill values in public
properties that are accessible outside
class even though the values are
actually filled in private values such
as ' _salary ' '_employeeID'.
We are able to change this as
this is defined as 'public' in
original class.
Don't worry we shall soon learn 'private' declaration too.
9
Class Employee
Private _employeeID As Integer
Private _salary As Double
Public Property EmployeeID() As Integer
Set(ByVal value As Integer)
_employeeID = value
End Set
Get
Return _employeeID
End Get
End Property
Public Property Salary() As Double
Set(ByVal value As Double)
_salary = value
End Set
Get
Return _salary
End Get
End Property
End Class
EncapsulationVB – Example Explanation
This has been defined as 'Private'. This
means that only code written inside
class Employee can modify it.
This is 'Public' as we would like to use a
way to change this property from an
object based on class Employee.
'Public' and 'Private' declarations are known
as access modifiers and they provide the
primary technique of ENCAPSULATION.
Are there other such modifiers? Surely Yes.
10
Class Employee
Private _employeeID As Integer
Private _salary As Double
Public Property EmployeeID() As Integer
Set(ByVal value As Integer)
_employeeID = value
End Set
Get
Return _employeeID
End Get
End Property
Public Property Salary() As Double
Set(ByVal value As Double)
_salary = value
End Set
Get
Return _salary
End Get
End Property
End Class
EncapsulationVB – Example Explanation for ABSTRACTION
Lets Focus on this class 'Employee'.
Suppose I have to define an additional
property 'employ_name' then it is most
likely that I shall define it within this
class.
Means to external world 'Employee' is
an abstract representation of all
behaviours(methods) and
states(properties) of employee and it is
supposed to encapsulate everything
related to this class.
So! Encapsulation helps to attain
ABSTRACTION. Abstraction also
means that class is just a template or a
map. Actual embodiment or physical
usage is where we create an object
based on a class.
11
Dim emp As New Employee
emp ._employeeID = 100
emp ._salary = 8500.3
Label1.Text = "Employee ID = " & emp ._employeeID.ToString()
Label2.Text = "Employee Salary = " & emp._salary.ToString()
Dim emp As New Employee
emp ._employeeID = 100
emp ._salary = 8500.3
Label1.Text = "Employee ID = " & emp ._employeeID.ToString()
Label2.Text = "Employee Salary = " & emp._salary.ToString()
EncapsulationCS – Error Trial
Make necessary changes here and 'Run' code.
Here we shall try to use the same
code with a change to try using
'Private' variable _employeeID
and _salary.
12
EncapsulationVB–Output after changing code
This program will generate a 'Compiler
Error Message: BC30390:
'Employee._employeeID' is not accessible as
it is 'Private'.
Here we see that variable '_employeeID' and '_salary' is actually hidden
behind the class ' Employee'. We can not initialize out side the class by using
object 'emp' of class 'Employee'.
This Error Output Actually proves that the concept of
'ENCAPSULATION' works. Code in Error but we are still very happy.
13
EncapsulationVB : Home Exercise
 You are required to make a program where you can declare a
class 'Mobile'.
 Make a public method sendsms( ).
 Make a protected method typetext( ).
 Call typetext( ) within sendsms( ).
 Now write some eventhandler to show functionality if protected could
be called outside class or not.
 Now further create a class derived from class 'mobile' and name it as
'iphone'.
 Try to use the typetext( ) method now.
We have told you about 'Private' and 'Public' access modifiers. Another common
access modifier used is 'Protected'
A 'Protected' access modifier allows access within a derived (child) class, but not
outside class.
Are there other access modifiers. Try to search internet to find-out and understand.
Difficult?. 'Facing Difficulties is the prime goal of a programmer'. Play some music
and relax. Next is just a summary slide.
14
EncapsulationVB : Learning Summary Review
 Concept of Encapsulation
 Encapsulation helps to provide controlled access to outside classes.
 Encapsulation also helps to bundle similar things together.
 Concept of Abstraction
 Encapsulation helps to attain Abstraction.
 Abstraction also relates to non-physical nature of classes.
 Trying to use a 'Private' data outside the class will give an
error. For this purpose 'Public' declaration should be done.
 A 'Protected' modifier is suitable for neat definition of access
restriction for access to derived classes only.
 Private properties or methods also serve an additional
purpose. If a property or method is private in a class means
the property or methods of same name can be freely
declared in another class.
15
 Ask and guide me at
sunmitraeducation@gmail.com
 Share this information with as
many people as possible.
 Keep visiting www.sunmitra.com
for programme updates.

Mais conteúdo relacionado

Mais procurados

Variables, expressions, standard types
 Variables, expressions, standard types  Variables, expressions, standard types
Variables, expressions, standard types Rubizza
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1Philip Schwarz
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2Philip Schwarz
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practicesManav Gupta
 
iOS best practices
iOS best practicesiOS best practices
iOS best practicesMaxim Vialyx
 
Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directivesAlexe Bogdan
 
Applicative Functor - Part 2
Applicative Functor - Part 2Applicative Functor - Part 2
Applicative Functor - Part 2Philip Schwarz
 
Unbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 LondonUnbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 LondonMathias Verraes
 
Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpecLewis Wright
 
How to get along with implicits
How to get along with implicits How to get along with implicits
How to get along with implicits Taisuke Oe
 
Oop php 5
Oop php 5Oop php 5
Oop php 5phpubl
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...FalafelSoftware
 

Mais procurados (20)

Variables, expressions, standard types
 Variables, expressions, standard types  Variables, expressions, standard types
Variables, expressions, standard types
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1
 
Monad Fact #6
Monad Fact #6Monad Fact #6
Monad Fact #6
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directives
 
Only oop
Only oopOnly oop
Only oop
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
Applicative Functor - Part 2
Applicative Functor - Part 2Applicative Functor - Part 2
Applicative Functor - Part 2
 
Unbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 LondonUnbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 London
 
Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpec
 
How to get along with implicits
How to get along with implicits How to get along with implicits
How to get along with implicits
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
 
Strings
StringsStrings
Strings
 
PHP-Part2
PHP-Part2PHP-Part2
PHP-Part2
 
Oop php 5
Oop php 5Oop php 5
Oop php 5
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
 

Semelhante a Programming Primer EncapsulationVB

Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxlorindajamieson
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstractionRaghav Chhabra
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces HomeWork-Fox
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
Use of Classes and functions#include iostreamusing name.docx
 Use of Classes and functions#include iostreamusing name.docx Use of Classes and functions#include iostreamusing name.docx
Use of Classes and functions#include iostreamusing name.docxaryan532920
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablescis247
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesNaresha K
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesccis224477
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablessdjdskjd9097
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 To Sum It Up
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Workhorse Computing
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docxgilbertkpeters11344
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfadityastores21
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classsdjdskjd9097
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 

Semelhante a Programming Primer EncapsulationVB (20)

Python classes objects
Python classes objectsPython classes objects
Python classes objects
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstraction
 
Python advance
Python advancePython advance
Python advance
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
Use of Classes and functions#include iostreamusing name.docx
 Use of Classes and functions#include iostreamusing name.docx Use of Classes and functions#include iostreamusing name.docx
Use of Classes and functions#include iostreamusing name.docx
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variables
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdf
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 

Mais de sunmitraeducation

Mais de sunmitraeducation (20)

Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Installing JDK and first java program
Installing JDK and first java programInstalling JDK and first java program
Installing JDK and first java program
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
 
Project1 CS
Project1 CSProject1 CS
Project1 CS
 
Grid Vew Control VB
Grid Vew Control VBGrid Vew Control VB
Grid Vew Control VB
 
Grid View Control CS
Grid View Control CSGrid View Control CS
Grid View Control CS
 
Ms Access
Ms AccessMs Access
Ms Access
 
Database Basics Theory
Database Basics TheoryDatabase Basics Theory
Database Basics Theory
 
Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3
 
Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3Visual Web Developer and Web Controls CS set 3
Visual Web Developer and Web Controls CS set 3
 
Progamming Primer Polymorphism (Method Overloading) VB
Progamming Primer Polymorphism (Method Overloading) VBProgamming Primer Polymorphism (Method Overloading) VB
Progamming Primer Polymorphism (Method Overloading) VB
 
Programming Primer Inheritance VB
Programming Primer Inheritance VBProgramming Primer Inheritance VB
Programming Primer Inheritance VB
 
Programming Primer Inheritance CS
Programming Primer Inheritance CSProgramming Primer Inheritance CS
Programming Primer Inheritance CS
 
ProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPSProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPS
 
Web Server Controls VB Set 1
Web Server Controls VB Set 1Web Server Controls VB Set 1
Web Server Controls VB Set 1
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
 
Web Controls Set-1
Web Controls Set-1Web Controls Set-1
Web Controls Set-1
 
Understanding IDEs
Understanding IDEsUnderstanding IDEs
Understanding IDEs
 
Html Server Image Control VB
Html Server Image Control VBHtml Server Image Control VB
Html Server Image Control VB
 
Html Server Image Control CS
Html Server Image Control CSHtml Server Image Control CS
Html Server Image Control CS
 

Último

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Último (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Programming Primer EncapsulationVB

  • 1. 1 A Programme Under the compumitra Series Programming Primer: Encapsulation and Abstraction LAB WORK GUIDE
  • 2. 2 OUTLINE  Encapsulation and Abstraction Using VB in asp.net Creating Example Event Handler. Example Output an Explanation. Home Exercise. Summary Review.
  • 4. 4 EncapsulationVB – Creating Button and Label Template Button with 'Text' Property set to 'Encapsulation'. Two Labels to hold the place for output display with 'text' property set to NULL (blank). • Follow Standard Website Creation Steps and set your path to C:Learner<student-id>ProgrammingPrimerEncapsulationVB • Now Create the Execution Event Handler as a button and output place holders as follows.
  • 5. 5 EncapsulationVB –Copy and Paste Code Go to 'Default.aspx.cs' and 'Paste' the Code in 'Button1_Click' handler. Copy this Code Dim emp As New Employee emp.EmployeeID = 100 emp.Salary = 8500.35 Label1.Text = "Employee ID = " & emp.EmployeeID.ToString() Label2.Text = "Employee Salary = " & emp.Salary.ToString() Dim emp As New Employee emp.EmployeeID = 100 emp.Salary = 8500.35 Label1.Text="Employee ID = " & emp.EmployeeID.ToString() Label2.Text="Employee Salary = " & emp.Salary.ToString()
  • 6. 6 EncapsulationVB –Copy Code Class Employee Private _employeeID As Integer Private _salary As Double Public Property EmployeeID() As Integer Set(ByVal value As Integer) _employeeID = value End Set Get Return _employeeID End Get End Property Public Property Salary() As Double Set(ByVal value As Double) _salary = value End Set Get Return _salary End Get End Property End Class Copy this Code
  • 7. 7 EncapsulationVB –Paste Code Run Code By pressing 'F5' Class Employee Private _employeeID As Integer Private _salary As Double Public Property EmployeeID() As Integer Set(ByVal value As Integer) _employeeID = value End Set Get Return _employeeID End Get End Property Public Property Salary() As Double Set(ByVal value As Double) _salary = value End Set Get Return _salary End Get End Property End Class Label1.Text = "Employee ID = " & emp.EmployeeID.ToString() Label2.Text = "Employee Salary = " & emp.Salary.ToString() Paste code after the End of '_Default' class
  • 8. 8 Employee emp = new Employee(); emp.EmployeeID = 100; emp.Salary = 8500.30; Label1.Text = emp.EmployeeID.ToString(); Label2.Text = emp.Salary.ToString(); EncapsulationVB –Output Output after executing the handler using the button. This 'output' is generated, because we are trying to fill values in public properties that are accessible outside class even though the values are actually filled in private values such as ' _salary ' '_employeeID'. We are able to change this as this is defined as 'public' in original class. Don't worry we shall soon learn 'private' declaration too.
  • 9. 9 Class Employee Private _employeeID As Integer Private _salary As Double Public Property EmployeeID() As Integer Set(ByVal value As Integer) _employeeID = value End Set Get Return _employeeID End Get End Property Public Property Salary() As Double Set(ByVal value As Double) _salary = value End Set Get Return _salary End Get End Property End Class EncapsulationVB – Example Explanation This has been defined as 'Private'. This means that only code written inside class Employee can modify it. This is 'Public' as we would like to use a way to change this property from an object based on class Employee. 'Public' and 'Private' declarations are known as access modifiers and they provide the primary technique of ENCAPSULATION. Are there other such modifiers? Surely Yes.
  • 10. 10 Class Employee Private _employeeID As Integer Private _salary As Double Public Property EmployeeID() As Integer Set(ByVal value As Integer) _employeeID = value End Set Get Return _employeeID End Get End Property Public Property Salary() As Double Set(ByVal value As Double) _salary = value End Set Get Return _salary End Get End Property End Class EncapsulationVB – Example Explanation for ABSTRACTION Lets Focus on this class 'Employee'. Suppose I have to define an additional property 'employ_name' then it is most likely that I shall define it within this class. Means to external world 'Employee' is an abstract representation of all behaviours(methods) and states(properties) of employee and it is supposed to encapsulate everything related to this class. So! Encapsulation helps to attain ABSTRACTION. Abstraction also means that class is just a template or a map. Actual embodiment or physical usage is where we create an object based on a class.
  • 11. 11 Dim emp As New Employee emp ._employeeID = 100 emp ._salary = 8500.3 Label1.Text = "Employee ID = " & emp ._employeeID.ToString() Label2.Text = "Employee Salary = " & emp._salary.ToString() Dim emp As New Employee emp ._employeeID = 100 emp ._salary = 8500.3 Label1.Text = "Employee ID = " & emp ._employeeID.ToString() Label2.Text = "Employee Salary = " & emp._salary.ToString() EncapsulationCS – Error Trial Make necessary changes here and 'Run' code. Here we shall try to use the same code with a change to try using 'Private' variable _employeeID and _salary.
  • 12. 12 EncapsulationVB–Output after changing code This program will generate a 'Compiler Error Message: BC30390: 'Employee._employeeID' is not accessible as it is 'Private'. Here we see that variable '_employeeID' and '_salary' is actually hidden behind the class ' Employee'. We can not initialize out side the class by using object 'emp' of class 'Employee'. This Error Output Actually proves that the concept of 'ENCAPSULATION' works. Code in Error but we are still very happy.
  • 13. 13 EncapsulationVB : Home Exercise  You are required to make a program where you can declare a class 'Mobile'.  Make a public method sendsms( ).  Make a protected method typetext( ).  Call typetext( ) within sendsms( ).  Now write some eventhandler to show functionality if protected could be called outside class or not.  Now further create a class derived from class 'mobile' and name it as 'iphone'.  Try to use the typetext( ) method now. We have told you about 'Private' and 'Public' access modifiers. Another common access modifier used is 'Protected' A 'Protected' access modifier allows access within a derived (child) class, but not outside class. Are there other access modifiers. Try to search internet to find-out and understand. Difficult?. 'Facing Difficulties is the prime goal of a programmer'. Play some music and relax. Next is just a summary slide.
  • 14. 14 EncapsulationVB : Learning Summary Review  Concept of Encapsulation  Encapsulation helps to provide controlled access to outside classes.  Encapsulation also helps to bundle similar things together.  Concept of Abstraction  Encapsulation helps to attain Abstraction.  Abstraction also relates to non-physical nature of classes.  Trying to use a 'Private' data outside the class will give an error. For this purpose 'Public' declaration should be done.  A 'Protected' modifier is suitable for neat definition of access restriction for access to derived classes only.  Private properties or methods also serve an additional purpose. If a property or method is private in a class means the property or methods of same name can be freely declared in another class.
  • 15. 15  Ask and guide me at sunmitraeducation@gmail.com  Share this information with as many people as possible.  Keep visiting www.sunmitra.com for programme updates.