Thursday, January 27, 2011

Abstraction & Encapsulation

Abstraction is the process of coining an interface that specifies all the
essential external behavior of an Object for a given client. This
interface is the external contract upon which the object's client depend
on. Abstraction focuses on the external view of an object and serves to
separate an object's behavior from its implementation.

Abstraction is based on concept of invariance - a boolean condition that
should be true at all times. Each method defines pre-conditions
(invariants the method assumes) and post-conditions (invariants that the
method satisfies).

Encapsulation is hiding of the implementation details of an object. An
object's client is not interested in the implementation details as long
as the implementation complies to the external contract.

Abstraction and Encapsulation are complementary concepts. Abstraction
focuses on the external behavior and encapsulation focuses on the
implementation that gives rise to the external behavior.

No comments: