2. Introduction
Encaptulation 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.
3. Why need encapsulation?
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.
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.
4. Why need encapsulation? (cont.. )
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.
public functions
private
functions
private data
5. 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.
7. Extensibility
Makes long term development easy.
Updates can be made by changing the
encapsulated part without changing the input and
output formats.
8. Kesimpulan
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.