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

Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaMadishetty Prathibha
 
encapsulation
encapsulationencapsulation
encapsulationshalini392
 
Abstraction
AbstractionAbstraction
Abstractionadil raja
 
OOP java
OOP javaOOP java
OOP javaxball977
 
Encapsulation
EncapsulationEncapsulation
EncapsulationFALLEE31188
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Encapsulation
EncapsulationEncapsulation
EncapsulationBurhan Ahmed
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsHarsh Patel
 

What's hot (20)

Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Java I/O
Java I/OJava I/O
Java I/O
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Association agggregation and composition
Association agggregation and compositionAssociation agggregation and composition
Association agggregation and composition
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
encapsulation
encapsulationencapsulation
encapsulation
 
Abstraction
AbstractionAbstraction
Abstraction
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Chapter2 Encapsulation (Java)
Chapter2 Encapsulation (Java)Chapter2 Encapsulation (Java)
Chapter2 Encapsulation (Java)
 
OOP java
OOP javaOOP java
OOP java
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 

Viewers also liked

Capsule technology [autosaved]
Capsule technology [autosaved]Capsule technology [autosaved]
Capsule technology [autosaved]Abd Rhman Gamil gamil
 
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
 
Capsules -Pharmaceutics
Capsules -PharmaceuticsCapsules -Pharmaceutics
Capsules -PharmaceuticsAreej Abu Hanieh
 
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
 
C++Presentation 2.PPT
C++Presentation 2.PPTC++Presentation 2.PPT
C++Presentation 2.PPTVENARATEKANHURU
 
27csharp
27csharp27csharp
27csharpSireesh K
 
Access specifier
Access specifierAccess specifier
Access specifierzindadili
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileLuis Goldster
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileJames Wong
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileHoang Nguyen
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileHarry Potter
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileFraboni Ec
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileYoung Alista
 
Abstraction file
Abstraction fileAbstraction file
Abstraction fileTony Nguyen
 
Assignment
AssignmentAssignment
Assignmentbhup_289
 

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
 
C# Encapsulation
C# EncapsulationC# Encapsulation
C# Encapsulation
 
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
 

More from Muhammad Hammad Waseem

[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++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 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its TypesMuhammad 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 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++Muhammad Hammad Waseem
 
[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++Muhammad 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 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++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
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data MemberMuhammad 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

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
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
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
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
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

[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