SlideShare a Scribd company logo
1 of 15
1
A Programme Under the compumitra Series
Programming Primer:
Encapsulation and Abstraction
LAB WORK GUIDE
2
OUTLINE
 Encapsulation and Abstraction Using
C# in asp.net
Creating Example Event Handler.
Example Output an Explanation.
Home Exercise.
Summary Review.
3
Encapsulation and Abstraction
Using C# in asp.net
4
EncapsulationCS – 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 from C# and set your path
to C:Learner<student-id>ProgrammingPrimerEncapsulationCS
• Now Create the Execution Event Handler as a button and output
place holders as follows.
5
EncapsulationCS –Copy and Paste Code
Go to 'Default.aspx.cs' and 'Paste' the Code in
'Button1_Click' handler.
Copy this Code
Employee emp = new Employee();
emp.EmployeeID = 100;
emp.Salary = 8500.30;
Label1.Text = "Employee ID = " + emp.EmployeeID.ToString();
Label2.Text = "Employee Salary = " + emp.Salary.ToString();
Employee emp = new Employee();
emp.EmployeeID = 100;
emp.Salary = 8500.30;
Label1.Text = "Employee ID = " + emp.EmployeeID.ToString() ;
Label2.Text = "Employee Salary = " + emp.Salary.ToString() ;
6
EncapsulationCS –Copy Code
class Employee
{
private int _employeeID;
private double _salary;
public int EmployeeID //Properties
{
set
{ _employeeID = value; }
get
{ return _employeeID; }
}
public double Salary //Properties
{
set
{ _salary = value; }
get
{ return _salary; }
}
}
Copy this Code
7
EncapsulationCS –Paste Code
Run Code By
pressing 'F5'
Paste code after the End
of '_Default' class
class Employee
{
private int _employeeID;
private double _salary;
public int EmployeeID //Properties
{
set
{ _employeeID = value; }
get
{ return _employeeID; }
}
public double Salary //Properties
{
set
{ _salary = value; }
get
{ return _salary; }
}
}
Label1.Text = emp.EmployeeID.ToString();
Label2.Text = emp.Salary.ToString();
8
Employee emp = new Employee();
emp.EmployeeID = 100;
emp.Salary = 8500.30;
Label1.Text = emp.EmployeeID.ToString();
Label2.Text = emp.Salary.ToString();
EncapsulationCS –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 int _employeeID;
private double _salary;
public int EmployeeID //Properties
{
set
{ _employeeID = value; }
get
{ return _employeeID; }
}
public double Salary //Properties
{
set
{ _salary = value; }
get
{ return _salary; }
}
}
EncapsulationCS – 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 int _employeeID;
private double _salary;
public int EmployeeID //Properties
{
set
{ _employeeID = value; }
get
{ return _employeeID; }
}
public double Salary //Properties
{
set
{ _salary = value; }
get
{ return _salary; }
}
}
EncapsulationCS – 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
emp._employeeID = 100;
emp._salary = 8500.30;
Label1.Text = "Employee ID = " + emp._employeeID.ToString();
Label2.Text = "Employee Salary = " + emp._employeeID.ToString();
emp._employeeID = 100;
emp._salary = 8500.30;
Label1.Text = "Employee ID = " + emp._employeeID.ToString();
Label2.Text = "Employee Salary = " +
emp._employeeID.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
EncapsulationCS–Output after changing code
This program will generate a 'Compiler
Error Message: CS0122:
'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
EncapsulationCS : 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
EncapsulationCS : 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.

More Related Content

What's hot

Test and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsTest and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsPierre MARTIN
 
Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Wildan Maulana
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1Philip Schwarz
 
De constructed-module
De constructed-moduleDe constructed-module
De constructed-moduleJames Cowie
 
Automated Refactoring
Automated RefactoringAutomated Refactoring
Automated RefactoringJaneve George
 
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...Philip Schwarz
 
Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpecLewis Wright
 
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2Philip Schwarz
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2Philip Schwarz
 
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
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascriptguest4d57e6
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)Chris Huang
 

What's hot (20)

Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Test and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP BehaviorsTest and API-driven development of CakePHP Behaviors
Test and API-driven development of CakePHP Behaviors
 
Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2Object Oriented Programming With PHP 5 #2
Object Oriented Programming With PHP 5 #2
 
Comp102 lec 4
Comp102   lec 4Comp102   lec 4
Comp102 lec 4
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1
 
De constructed-module
De constructed-moduleDe constructed-module
De constructed-module
 
Automated Refactoring
Automated RefactoringAutomated Refactoring
Automated Refactoring
 
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
Diffing Shotgun Surgery and Divergent Change smells in the two editions of Re...
 
Monad Fact #6
Monad Fact #6Monad Fact #6
Monad Fact #6
 
Dsl
DslDsl
Dsl
 
Factory Girl
Factory GirlFactory Girl
Factory Girl
 
Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpec
 
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 2
 
Objective-c Runtime
Objective-c RuntimeObjective-c Runtime
Objective-c Runtime
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2
 
How to get along with implicits
How to get along with implicits How to get along with implicits
How to get along with implicits
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 

Similar to Programming Primer Encapsulation CS

Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstractionRaghav Chhabra
 
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
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Manykenatmxm
 
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
 
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
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
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
 
Task 2
Task 2Task 2
Task 2EdiPHP
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
 

Similar to Programming Primer Encapsulation CS (20)

Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstraction
 
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
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
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
 
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
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
chapt02 (1).ppt
chapt02 (1).pptchapt02 (1).ppt
chapt02 (1).ppt
 
chapt02.ppt
chapt02.pptchapt02.ppt
chapt02.ppt
 
C++chapt002a.ppt
C++chapt002a.pptC++chapt002a.ppt
C++chapt002a.ppt
 
cht02.ppt
cht02.pptcht02.ppt
cht02.ppt
 
chapt02.ppt
chapt02.pptchapt02.ppt
chapt02.ppt
 
Python advance
Python advancePython advance
Python advance
 
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
 
Task 2
Task 2Task 2
Task 2
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 

More from sunmitraeducation

More from 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
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 

Programming Primer Encapsulation CS

  • 1. 1 A Programme Under the compumitra Series Programming Primer: Encapsulation and Abstraction LAB WORK GUIDE
  • 2. 2 OUTLINE  Encapsulation and Abstraction Using C# in asp.net Creating Example Event Handler. Example Output an Explanation. Home Exercise. Summary Review.
  • 4. 4 EncapsulationCS – 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 from C# and set your path to C:Learner<student-id>ProgrammingPrimerEncapsulationCS • Now Create the Execution Event Handler as a button and output place holders as follows.
  • 5. 5 EncapsulationCS –Copy and Paste Code Go to 'Default.aspx.cs' and 'Paste' the Code in 'Button1_Click' handler. Copy this Code Employee emp = new Employee(); emp.EmployeeID = 100; emp.Salary = 8500.30; Label1.Text = "Employee ID = " + emp.EmployeeID.ToString(); Label2.Text = "Employee Salary = " + emp.Salary.ToString(); Employee emp = new Employee(); emp.EmployeeID = 100; emp.Salary = 8500.30; Label1.Text = "Employee ID = " + emp.EmployeeID.ToString() ; Label2.Text = "Employee Salary = " + emp.Salary.ToString() ;
  • 6. 6 EncapsulationCS –Copy Code class Employee { private int _employeeID; private double _salary; public int EmployeeID //Properties { set { _employeeID = value; } get { return _employeeID; } } public double Salary //Properties { set { _salary = value; } get { return _salary; } } } Copy this Code
  • 7. 7 EncapsulationCS –Paste Code Run Code By pressing 'F5' Paste code after the End of '_Default' class class Employee { private int _employeeID; private double _salary; public int EmployeeID //Properties { set { _employeeID = value; } get { return _employeeID; } } public double Salary //Properties { set { _salary = value; } get { return _salary; } } } Label1.Text = emp.EmployeeID.ToString(); Label2.Text = emp.Salary.ToString();
  • 8. 8 Employee emp = new Employee(); emp.EmployeeID = 100; emp.Salary = 8500.30; Label1.Text = emp.EmployeeID.ToString(); Label2.Text = emp.Salary.ToString(); EncapsulationCS –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 int _employeeID; private double _salary; public int EmployeeID //Properties { set { _employeeID = value; } get { return _employeeID; } } public double Salary //Properties { set { _salary = value; } get { return _salary; } } } EncapsulationCS – 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 int _employeeID; private double _salary; public int EmployeeID //Properties { set { _employeeID = value; } get { return _employeeID; } } public double Salary //Properties { set { _salary = value; } get { return _salary; } } } EncapsulationCS – 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 emp._employeeID = 100; emp._salary = 8500.30; Label1.Text = "Employee ID = " + emp._employeeID.ToString(); Label2.Text = "Employee Salary = " + emp._employeeID.ToString(); emp._employeeID = 100; emp._salary = 8500.30; Label1.Text = "Employee ID = " + emp._employeeID.ToString(); Label2.Text = "Employee Salary = " + emp._employeeID.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 EncapsulationCS–Output after changing code This program will generate a 'Compiler Error Message: CS0122: '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 EncapsulationCS : 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 EncapsulationCS : 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.