KEMBAR78
Chapter2 Encapsulation (Java) | PDF
Chapter 2

Encapsulation

Dyah Fajar Nur Rohmah
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.
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.
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
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.
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.
Kesimpulan (cont.. .)
Encapsulation makes the programing code:

Flexi
ble

Main
taina
ble

Exte
nsibl
e
Thank You

Reference from:
Githushan Gengaparam - Madhusoothanan
Lakshitha Imbulpitiya - Sudheera Karunaratne

Chapter2 Encapsulation (Java)

  • 1.
  • 2.
    Introduction Encaptulation is thetechnique 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? Combiningdata 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 aboundary 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.
  • 6.
    Flexibility Encapsulation makes thecode easier to visualize. This means codes can be arranged “visually” before implementing.
  • 7.
    Extensibility Makes long termdevelopment easy. Updates can be made by changing the encapsulated part without changing the input and output formats.
  • 8.
    Kesimpulan Encapsulation is thetechnique 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.
  • 9.
    Kesimpulan (cont.. .) Encapsulationmakes the programing code: Flexi ble Main taina ble Exte nsibl e
  • 10.
    Thank You Reference from: GithushanGengaparam - Madhusoothanan Lakshitha Imbulpitiya - Sudheera Karunaratne