SlideShare a Scribd company logo
1 of 14
Encapsulation




                Githushan Gengaparam
                   Madhusoothanan
                 Lakshitha Imbulpitiya
                Sudheera Karunaratne
Encapsulation
 Inheritance




Polymorphism   Abstraction
 Encapsulation   is the technique of making the
  fields in a class private and providing access
  to the fields via public methods.
 Encapsulation also can be described as a
  protective barrier that prevents the code and
  data being randomly accessed by other code
  defined outside the class.
   To hide the internal implementation details of the
    class

   Can safely modified the implementation without
    worrying breaking the existing code that uses the
    class

   Protect class against accidental/ willful stupidity

   Keeps class tidy by keeping the visible fields to a
    minimum

   Easier to use and understand
    In object-oriented programming data encapsulation is
     concerned with;
1.    Combining data and how it's manipulated in one place :
      This is achieved through the state (the private fields)
      and the behaviors (the public methods) of an object.

2.    Only allowing the state of an object to be accessed and
      modified through behaviors: The values contained within
      an object's state can then be strictly controlled.

3.    Hiding the details of how the object works: The only
      part of the object that is accessible to the outside world
      is its behaviors. What happens inside those behaviors
      and how the state is stored is hidden from view.
 The  main benefit of encapsulation is the
  ability to modify our implemented code
  without breaking the code of others who use
  our code.
 With this feature Encapsulation gives
  maintainability, flexibility and extensibility
  to the code.
   The fields of a class can be made read-only or
    write- only

   A class can have total control over what is stored
    in its fields

   The users of a class do not know how the class
    stores its data.

   A class can change the data type of a fields, and
    a users of the class do not need to change any of
    their code
 Encapsulation  draws a boundary around a set
  of data and method.
 This allows a developer to use the code
  without having to know how it works, but
  with what input data and its input data range
  and with what it returns.
 Encapsulation   makes the code easier to
  visualize.
 This means codes can be arranged “visually”
  before implementing.
 Makes long term development easy.
 Updates can be made by changing the
  encapsulated part without changing the input
  and output formats.
Item <<abstract>>
                         # code : String
                         # title : String
                         # year : int
                         # baseFine : float
                         + setBaseFine(float) : void
                         + toString() : String
                         + abstract getFine(int) : float




  Book <<entity>>              Video <<entity>>             Audio <<entity>>
                             - producer: String
- author : String            - distributer: String         - artist: String
- publisher : String         - cast: String                - genre : String
                             - duration: float

+ toString() : String        + toString() : String         + toString() : String
+ getFine(int) : float       + getFine(int) : float        + getFine(int) : float
 Encapsulation  is the technique of making the
 fields in a class private and providing access
 to the fields via public methods.

 The main benefit of encapsulation is the
 ability to modify the implemented code
 without breaking the code of others who use
 the implemented code.
 Encapsulation   makes the programing code;




                  Flexible


                              Extensible

                  Maintaina
                     ble
Encapsulation

More Related Content

What's hot

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Paumil Patel
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxLecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxShahinAhmed49
 
Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++vivekkumar2938
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programmingAmar Jukuntla
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingIqra khalil
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
Java package
Java packageJava package
Java packageCS_GDRCST
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops conceptsNilesh Dalvi
 

What's hot (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxLecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
 
Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++
 
encapsulation
encapsulationencapsulation
encapsulation
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Java package
Java packageJava package
Java package
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
concept of oops
concept of oopsconcept of oops
concept of oops
 

Viewers also liked

Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract ClassOUM SAOKOSAL
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop pptdaxesh chauhan
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...cprogrammings
 

Viewers also liked (6)

Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Inheritance
InheritanceInheritance
Inheritance
 

Similar to Encapsulation

Similar to Encapsulation (20)

Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
C++ programing lanuage
C++ programing lanuageC++ programing lanuage
C++ programing lanuage
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
 
Benefits of encapsulation
Benefits of encapsulationBenefits of encapsulation
Benefits of encapsulation
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptxOOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptx
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
 
Four Pillers Of OOPS
Four Pillers Of OOPSFour Pillers Of OOPS
Four Pillers Of OOPS
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ Programming
 
encapsulation1-150816163959-lva1-app6891.pdf
encapsulation1-150816163959-lva1-app6891.pdfencapsulation1-150816163959-lva1-app6891.pdf
encapsulation1-150816163959-lva1-app6891.pdf
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
gxhrehsrejhvytftfltyflytdtydtydky5dyrdtrdrdtrd
gxhrehsrejhvytftfltyflytdtydtydky5dyrdtrdrdtrdgxhrehsrejhvytftfltyflytdtydtydky5dyrdtrdrdtrd
gxhrehsrejhvytftfltyflytdtydtydky5dyrdtrdrdtrd
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
My c++
My c++My c++
My c++
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 

Recently uploaded

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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
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
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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
 

Recently uploaded (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
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"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 

Encapsulation

  • 1. Encapsulation Githushan Gengaparam Madhusoothanan Lakshitha Imbulpitiya Sudheera Karunaratne
  • 3.  Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.  Encapsulation also can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class.
  • 4. To hide the internal implementation details of the class  Can safely modified the implementation without worrying breaking the existing code that uses the class  Protect class against accidental/ willful stupidity  Keeps class tidy by keeping the visible fields to a minimum  Easier to use and understand
  • 5. In object-oriented programming data encapsulation is concerned with; 1. Combining data and how it's manipulated in one place : This is achieved through the state (the private fields) and the behaviors (the public methods) of an object. 2. Only allowing the state of an object to be accessed and modified through behaviors: The values contained within an object's state can then be strictly controlled. 3. Hiding the details of how the object works: The only part of the object that is accessible to the outside world is its behaviors. What happens inside those behaviors and how the state is stored is hidden from view.
  • 6.  The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code.  With this feature Encapsulation gives maintainability, flexibility and extensibility to the code.
  • 7. The fields of a class can be made read-only or write- only  A class can have total control over what is stored in its fields  The users of a class do not know how the class stores its data.  A class can change the data type of a fields, and a users of the class do not need to change any of their code
  • 8.  Encapsulation draws a boundary around a set of data and method.  This allows a developer to use the code without having to know how it works, but with what input data and its input data range and with what it returns.
  • 9.  Encapsulation makes the code easier to visualize.  This means codes can be arranged “visually” before implementing.
  • 10.  Makes long term development easy.  Updates can be made by changing the encapsulated part without changing the input and output formats.
  • 11. Item <<abstract>> # code : String # title : String # year : int # baseFine : float + setBaseFine(float) : void + toString() : String + abstract getFine(int) : float Book <<entity>> Video <<entity>> Audio <<entity>> - producer: String - author : String - distributer: String - artist: String - publisher : String - cast: String - genre : String - duration: float + toString() : String + toString() : String + toString() : String + getFine(int) : float + getFine(int) : float + getFine(int) : float
  • 12.  Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.  The main benefit of encapsulation is the ability to modify the implemented code without breaking the code of others who use the implemented code.
  • 13.  Encapsulation makes the programing code; Flexible Extensible Maintaina ble