Skip to content
On this page

Encapsulation

A quick detour: an oven is an object! A lot is going on inside an oven but you interact with it through certain set operations. You, for example, can set the temperature of an oven and thus change its state (temperature). How an oven exactly operates is not your concern. An oven is, in some sense, a "black box" to you.

Objects, in software as in real-life, are built in a way to encapsulate their state and behavior in a unit (a bundle, a capsule, a black box, ...) with an interface to allow (and simplify) access for the user.

Class is a unit of encapsulation in OOP; it provides the machinery for bundling state and behavior (data fields and methods that work on that data) within one unit.

The state is typically private to the object and not (directly) visible to clients. This concept of denying direct access to the state of an object is called information hiding.

In addition to the state, some of the behavior (responsibilities) of an object may also be hidden and only used by the object.

INFO

The set of visible (public) behavior of an object from its interface and define how it collaborates (acts and reacts) with other objects.

Released under the MIT License.