Encapsulation

The Dictionary of the Object Technology defines encapsulation as: "The physical location of features (properties, behaviors) into a single black box abstraction that hides their implementation behind a public interface."

Often, encapsulation is referred to as "information hiding." An object "hides" the implementation of its behavior behind its interface or its "public face." Other objects can use its behavior without having detailed knowledge of its implementation. Objects know only the kind of operations they can request other objects to perform. This allows software designers to abstract from irrelevant details and concentrate on what objects will perform.

An important advantage of encapsulation is the elimination of direct dependencies on a particular implementation of an object's behavior. The object is known from its interface and clients can use the object's behavior by only having knowledge of its interface. The particular implementation of an object's interface is not important. Therefore, the implementation of the object's behavior can change any time without affecting the object's use. Encapsulation helps manage complexity by identifying a coherent part of this complexity and assigning it to individual objects.

The fact that an object hides the implementation of its behavior by exposing only its "public face" could be beneficial to other objects that need its behavior. The "interested" objects could consider more than one option while looking for a specific functionality that satisfies their needs. They need only to "examine" the interfaces of candidate objects. Objects with similar behavior could serve as substitutes to each other.

0 0

Post a comment