Upload
githu-shan
View
1.400
Download
0
Tags:
Embed Size (px)
DESCRIPTION
A short presentation about EncapsulationOCJP Batch 27
Citation preview
Enca
psul
atio
n
Githushan GengaparamMadhusoothanan
Lakshitha ImbulpitiyaSudheera Karunaratne
INTRODUCTION
Encapsulation
Abstraction
Polymorphism
Inheritance
OBJECT ORIENTED PROGRAMING (OOP) CONCEPTS
INTRODUCTION 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.
IMPORTANCE OF ENCAPSULATION 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
WHY NEED ENCAPSULATION? 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.
BENEFITS 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.
BENEFITS OF HAVING ENCAPSULATION
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
MAINTAINABILITY 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.
FLEXIBILITY Encapsulation makes the code easier to
visualize. This means codes can be arranged
“visually” before implementing.
EXTENSIBILITY Makes long term development easy. Updates can be made by changing the
encapsulated part without changing the input and output formats.
LIBRARY SYSTEM
+ setBaseFine(float) : void+ toString() : String+ abstract getFine(int) : float
Item <<abstract>># code : String # title : String # year : int # baseFine : float
+ toString() : String+ getFine(int) : float
Book <<entity>>
- author : String- publisher : String
+ toString() : String+ getFine(int) : float
Video <<entity>>
- producer: String- distributer: String- cast: String- duration: float
+ toString() : String+ getFine(int) : float
Audio <<entity>>
- artist: String- genre : String
CONCLUSION
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.
CONCLUSION Encapsulation makes the programing
code;
Maintainable
Extensible
Flexible