SlideShare a Scribd company logo
1 of 14
Encapsulation
(Information Hiding)
Speaker: Muhammad Hammad Waseem
m.hammad.wasim@gmail.com
Encapsulation
• “ to enclose in or as in a capsule ”
• The object-oriented meaning of encapsulation is
• to enclose related data, routines and definitions in a class capsule. This does not
necessarily mean hiding. (Mish)
• Encapsulation is the ‘bundling together’ of data and
behavior so that they are inseparable. (Mcgraw Hill)
Why Encapsulation called Information Hiding
• Encapsulation (also called information hiding) consists of separating
the external aspects of an object, from the internal implementation
details of the object, which are hidden from other objects.
• Encapsulation prevents a program from becoming to interdependent
that a small change has massive ripple effects.
• Encapsulation has ability to combine data structure and behavior in a
single entity makes encapsulation cleaner and more powerful than in
conventional languages that separate data structure and behavior.
Information Hiding
• Information Hiding: a module is characterized by the information it
hides from other modules, which are called its clients. The hidden
information remains a secret to the client modules. (Ghezzi et al)
• Information hiding is the principle that users of a software component
(such as a class) need to know only the essential details of how to
initialize and access the component, and do not need to know the
details of the implementation. (Budd)
What Encapsulation Provides in OO?
• The interface is the visible surface of the capsule.
• The interface describes the essential characteristics of objects of the class
which are visible to the exterior world.
• Interface data – which should be visible from outside/other class or method.
• The implementation is hidden in the capsule.
• The implementation hiding means that data can only be manipulated, that is
updated, within the class, but it does not mean hiding interface data.
• Implementation data – which should be hidden from outside/other class or
method.
General 3 Ways to Encapsulate
Data
Public Member Access Specifier
Private Member Access Specifier
Protected Member Access Specifier
Public Member Access Specifier
• Syntax
• public: <declarations>
• Description:
• A public member can be accessed by any function.
• Members of a struct or union are public by default.
• You can override the default struct access with private or protected but you
cannot override the default union access.
• Friend declarations are not affected by these access specifiers.
Private Member Access Specifier
• Syntax
• private: <declarations>
• Description:
• A private member can be accessed only by member functions and friends of
the class in which it is declared.
• Class members are private by default.
• You can override the default struct access with private or protected but you
cannot override the default union access.
• Friend declarations are not affected by these access specifiers.
Protect Member Access Specifier
• Syntax
• protected: <declarations>
• Description:
• A protected member can be accessed by member functions and friends of the
class in which it was declared, and by classes derived (derived classes) from
the declared class.
• You can override the default struct access with private or protected but you
cannot override the default union access.
• Friend declarations are not affected by these access specifiers.
Example: Access Specifiers
class MyClass
{
public: //access from anywhere
int x;
private: //only access from within a class
int y;
protected: //access from within a class ,or derived class
int z;
};
void main()
{
MyClass CopyClass;
CopyClass.x = 1; //OK, Public Access.
CopyClass.y = 2; //Error! Y isn't a member of MyClass
CopyClass.z = 3; //Error! Z isn't a member of MyClass
}
Advantage of Encapsulation
• It prevents others accessing the insides of an object.
• The only thing that can manipulate the data in an object is that object’s
method or member function.
• It main aim is to prevent accident.
• It builds a protective wall (encapsulation) around the member data and
member function of the class, and hiding implementation details of object. So
It keeps data safe from accident.
Example: Encapsulation Or Information Hiding
(1/3)
#include <iostream>
// Declaration of the Box class.
class Box
{
private:
int height, width, depth; // private data members.
public:
Box(int, int, int);// constructor function.
~Box(); // destructor function.
int volume(); // member function (compute volume).
};
Example: Encapsulation Or Information Hiding
(2/3)
// Definition of the Box class.
Box::Box(int ht, int wd, int dp)// The constructor function.
{
height = ht;
width = wd;
depth = dp;
}
Box::~Box() //The destructor function. Use of scope resolution ‘::’
{
// does nothing
}
int Box::volume() // Member function to compute the Box's volume.
{
return height * width * depth;
}
Example: Encapsulation Or Information Hiding
(3/3)
// The main() function.
int main()
{
// Construct a Box object.
Box thisbox(7, 8, 9); // actual values
// Compute and display the object's volume.
int volume = thisbox.volume();
cout << “output volume is : “ << volume;
return 0;
}
RESULT:
output volume is: 504

More Related Content

What's hot

Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaMOHIT AGARWAL
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented ProgrammingAida Ramlan II
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++Hitesh Kumar
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Modelsohailsaif
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programmingSachin Sharma
 
Event handling
Event handlingEvent handling
Event handlingswapnac12
 

What's hot (20)

Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Association agggregation and composition
Association agggregation and compositionAssociation agggregation and composition
Association agggregation and composition
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Interface in java
Interface in javaInterface in java
Interface in java
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Java packages
Java packagesJava packages
Java packages
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
 
Event handling
Event handlingEvent handling
Event handling
 

Viewers also liked

Soft gelatin capsule
Soft gelatin capsuleSoft gelatin capsule
Soft gelatin capsuleArafat Jakir
 
Encapsulation_ Problem and Remedies
Encapsulation_ Problem and RemediesEncapsulation_ Problem and Remedies
Encapsulation_ Problem and RemediesBhushan Ghike
 
An overview of encapsulation technologies for food
An overview of encapsulation technologies for foodAn overview of encapsulation technologies for food
An overview of encapsulation technologies for foodnooshin noshirvani
 
Flavor encapsulation assignment
Flavor encapsulation assignmentFlavor encapsulation assignment
Flavor encapsulation assignmentArun Kumar Gupta
 
Capsule Products Machines Manufacturer
Capsule Products Machines ManufacturerCapsule Products Machines Manufacturer
Capsule Products Machines ManufacturerSonuS International
 
Cgn280 semi automatic capsule filling machine
Cgn280 semi automatic capsule filling machineCgn280 semi automatic capsule filling machine
Cgn280 semi automatic capsule filling machineSky Yang
 
Validation of solid dosage forms in pharmaceutical industries
Validation of solid dosage forms in pharmaceutical industries Validation of solid dosage forms in pharmaceutical industries
Validation of solid dosage forms in pharmaceutical industries rasika walunj
 
Process validation of capsules
Process validation of capsulesProcess validation of capsules
Process validation of capsulespritam kumbhar
 
Small scale and large scale capsule filling machine
Small scale and large scale capsule filling machineSmall scale and large scale capsule filling machine
Small scale and large scale capsule filling machineceutics1315
 
Microencapsulation.....in pharmacy by sandeep
Microencapsulation.....in pharmacy   by sandeepMicroencapsulation.....in pharmacy   by sandeep
Microencapsulation.....in pharmacy by sandeepMollidain Sandeep
 
Pharmaceutical Capsules
Pharmaceutical CapsulesPharmaceutical Capsules
Pharmaceutical Capsulesjojohen
 

Viewers also liked (17)

Capsule technology [autosaved]
Capsule technology [autosaved]Capsule technology [autosaved]
Capsule technology [autosaved]
 
Soft gelatin capsule
Soft gelatin capsuleSoft gelatin capsule
Soft gelatin capsule
 
Encapsulation_ Problem and Remedies
Encapsulation_ Problem and RemediesEncapsulation_ Problem and Remedies
Encapsulation_ Problem and Remedies
 
An overview of encapsulation technologies for food
An overview of encapsulation technologies for foodAn overview of encapsulation technologies for food
An overview of encapsulation technologies for food
 
Capsules -Pharmaceutics
Capsules -PharmaceuticsCapsules -Pharmaceutics
Capsules -Pharmaceutics
 
Flavor encapsulation assignment
Flavor encapsulation assignmentFlavor encapsulation assignment
Flavor encapsulation assignment
 
Capsule
CapsuleCapsule
Capsule
 
Capsule Products Machines Manufacturer
Capsule Products Machines ManufacturerCapsule Products Machines Manufacturer
Capsule Products Machines Manufacturer
 
Cgn280 semi automatic capsule filling machine
Cgn280 semi automatic capsule filling machineCgn280 semi automatic capsule filling machine
Cgn280 semi automatic capsule filling machine
 
Validation of solid dosage forms in pharmaceutical industries
Validation of solid dosage forms in pharmaceutical industries Validation of solid dosage forms in pharmaceutical industries
Validation of solid dosage forms in pharmaceutical industries
 
Process validation of capsules
Process validation of capsulesProcess validation of capsules
Process validation of capsules
 
Small scale and large scale capsule filling machine
Small scale and large scale capsule filling machineSmall scale and large scale capsule filling machine
Small scale and large scale capsule filling machine
 
Microencapsulation.....in pharmacy by sandeep
Microencapsulation.....in pharmacy   by sandeepMicroencapsulation.....in pharmacy   by sandeep
Microencapsulation.....in pharmacy by sandeep
 
Controlled Release Oral Drug Delivery System
Controlled Release Oral Drug Delivery SystemControlled Release Oral Drug Delivery System
Controlled Release Oral Drug Delivery System
 
Pharmaceutical Capsules
Pharmaceutical CapsulesPharmaceutical Capsules
Pharmaceutical Capsules
 
Capsules
CapsulesCapsules
Capsules
 
Capsule's
Capsule'sCapsule's
Capsule's
 

Similar to [OOP - Lec 08] Encapsulation (Information Hiding)

Encapsulation and inheritance
Encapsulation and inheritanceEncapsulation and inheritance
Encapsulation and inheritanceChaudhary Kashif
 
Encapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pillerEncapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pilleran7539661
 
Encapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pillerEncapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pilleran7539661
 
Access specifier
Access specifierAccess specifier
Access specifierzindadili
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileJames Wong
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileFraboni Ec
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileTony Nguyen
 
Assignment
AssignmentAssignment
Assignmentbhup_289
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”IOSR Journals
 

Similar to [OOP - Lec 08] Encapsulation (Information Hiding) (20)

Encapsulation and inheritance
Encapsulation and inheritanceEncapsulation and inheritance
Encapsulation and inheritance
 
Encapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pillerEncapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important piller
 
Encapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important pillerEncapsulation C++ Piller of OOP it is the important piller
Encapsulation C++ Piller of OOP it is the important piller
 
C++Presentation 2.PPT
C++Presentation 2.PPTC++Presentation 2.PPT
C++Presentation 2.PPT
 
27c
27c27c
27c
 
27csharp
27csharp27csharp
27csharp
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Access specifier
Access specifierAccess specifier
Access specifier
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
OOP.ppt
OOP.pptOOP.ppt
OOP.ppt
 
Assignment
AssignmentAssignment
Assignment
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
 
"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”"Study of Java Access Control Mechanism”
"Study of Java Access Control Mechanism”
 

More from Muhammad Hammad Waseem

[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++Muhammad Hammad Waseem
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to PointersMuhammad Hammad Waseem
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++Muhammad Hammad Waseem
 
[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++Muhammad Hammad Waseem
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)Muhammad Hammad Waseem
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of PrecedenceMuhammad Hammad Waseem
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++Muhammad Hammad Waseem
 
[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++Muhammad Hammad Waseem
 
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
[ITP - Lecture 02] Steps to Create Program & Approaches of ProgrammingMuhammad Hammad Waseem
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming LanguagesMuhammad Hammad Waseem
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 

More from Muhammad Hammad Waseem (20)

[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
[ITP - Lecture 14] Recursion
[ITP - Lecture 14] Recursion[ITP - Lecture 14] Recursion
[ITP - Lecture 14] Recursion
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
 
[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)
 
[ITP - Lecture 07] Comments in C/C++
[ITP - Lecture 07] Comments in C/C++[ITP - Lecture 07] Comments in C/C++
[ITP - Lecture 07] Comments in C/C++
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes[ITP - Lecture 05] Datatypes
[ITP - Lecture 05] Datatypes
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++[ITP - Lecture 03] Introduction to C/C++
[ITP - Lecture 03] Introduction to C/C++
 
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
[ITP - Lecture 02] Steps to Create Program & Approaches of Programming
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

[OOP - Lec 08] Encapsulation (Information Hiding)

  • 1. Encapsulation (Information Hiding) Speaker: Muhammad Hammad Waseem m.hammad.wasim@gmail.com
  • 2. Encapsulation • “ to enclose in or as in a capsule ” • The object-oriented meaning of encapsulation is • to enclose related data, routines and definitions in a class capsule. This does not necessarily mean hiding. (Mish) • Encapsulation is the ‘bundling together’ of data and behavior so that they are inseparable. (Mcgraw Hill)
  • 3. Why Encapsulation called Information Hiding • Encapsulation (also called information hiding) consists of separating the external aspects of an object, from the internal implementation details of the object, which are hidden from other objects. • Encapsulation prevents a program from becoming to interdependent that a small change has massive ripple effects. • Encapsulation has ability to combine data structure and behavior in a single entity makes encapsulation cleaner and more powerful than in conventional languages that separate data structure and behavior.
  • 4. Information Hiding • Information Hiding: a module is characterized by the information it hides from other modules, which are called its clients. The hidden information remains a secret to the client modules. (Ghezzi et al) • Information hiding is the principle that users of a software component (such as a class) need to know only the essential details of how to initialize and access the component, and do not need to know the details of the implementation. (Budd)
  • 5. What Encapsulation Provides in OO? • The interface is the visible surface of the capsule. • The interface describes the essential characteristics of objects of the class which are visible to the exterior world. • Interface data – which should be visible from outside/other class or method. • The implementation is hidden in the capsule. • The implementation hiding means that data can only be manipulated, that is updated, within the class, but it does not mean hiding interface data. • Implementation data – which should be hidden from outside/other class or method.
  • 6. General 3 Ways to Encapsulate Data Public Member Access Specifier Private Member Access Specifier Protected Member Access Specifier
  • 7. Public Member Access Specifier • Syntax • public: <declarations> • Description: • A public member can be accessed by any function. • Members of a struct or union are public by default. • You can override the default struct access with private or protected but you cannot override the default union access. • Friend declarations are not affected by these access specifiers.
  • 8. Private Member Access Specifier • Syntax • private: <declarations> • Description: • A private member can be accessed only by member functions and friends of the class in which it is declared. • Class members are private by default. • You can override the default struct access with private or protected but you cannot override the default union access. • Friend declarations are not affected by these access specifiers.
  • 9. Protect Member Access Specifier • Syntax • protected: <declarations> • Description: • A protected member can be accessed by member functions and friends of the class in which it was declared, and by classes derived (derived classes) from the declared class. • You can override the default struct access with private or protected but you cannot override the default union access. • Friend declarations are not affected by these access specifiers.
  • 10. Example: Access Specifiers class MyClass { public: //access from anywhere int x; private: //only access from within a class int y; protected: //access from within a class ,or derived class int z; }; void main() { MyClass CopyClass; CopyClass.x = 1; //OK, Public Access. CopyClass.y = 2; //Error! Y isn't a member of MyClass CopyClass.z = 3; //Error! Z isn't a member of MyClass }
  • 11. Advantage of Encapsulation • It prevents others accessing the insides of an object. • The only thing that can manipulate the data in an object is that object’s method or member function. • It main aim is to prevent accident. • It builds a protective wall (encapsulation) around the member data and member function of the class, and hiding implementation details of object. So It keeps data safe from accident.
  • 12. Example: Encapsulation Or Information Hiding (1/3) #include <iostream> // Declaration of the Box class. class Box { private: int height, width, depth; // private data members. public: Box(int, int, int);// constructor function. ~Box(); // destructor function. int volume(); // member function (compute volume). };
  • 13. Example: Encapsulation Or Information Hiding (2/3) // Definition of the Box class. Box::Box(int ht, int wd, int dp)// The constructor function. { height = ht; width = wd; depth = dp; } Box::~Box() //The destructor function. Use of scope resolution ‘::’ { // does nothing } int Box::volume() // Member function to compute the Box's volume. { return height * width * depth; }
  • 14. Example: Encapsulation Or Information Hiding (3/3) // The main() function. int main() { // Construct a Box object. Box thisbox(7, 8, 9); // actual values // Compute and display the object's volume. int volume = thisbox.volume(); cout << “output volume is : “ << volume; return 0; } RESULT: output volume is: 504