Tuesday, 23 October 2012

Encapsulation AND Abstraction in Object Oriented Design

While migration of Procedural System Design to Object Oriented System design has taken place since the paradigm shift, developer often face the challenges to adapt the shift. For some, the terms; Object Oriented (OO) sounds unfamiliar terms to them. Base on object, OO System Design offers various advantages as compare to her predecessor. One of the louded advantage include the term Abstraction

Abstraction is a term used to define approach to hide non-essential information of an item (either data, operation or even class). Abstraction is important to allow simplicity and to improve visible of the item (data, operation and class). Thus, a class present herself only the essential items which are useful to other classes. This approach as well is known as information hiding. Please be reminded this way; we should ask WHAT to order when we go for dinner but we will never ask HOW the food is being prepared. This is similar to Abstraction approach.

Why does information hiding so important? This is to reduce complexity. Imagine, if you wish to eat an apple, do we really really intend to know how the apple is planted and later harvested and reach to to your hand? Our objective is to eat an apple and not how the apple is planted. By hiding non-important/ non-essential information, our communication with the apple is simplify. On top of this, the apple seller can change how they stock up their apple without worrying if you will or not buying the apple. Object to object communication should be as simple as possible without worrying how the object carry out the method/ task/ behave. In another way, by adopting class abstraction, we are able to protect our content (data, operation or class).

While Abstraction promotes information hiding, Encapsulation is an approach to control access to the item (data, operation or class). Even with Abstraction, a proper access control to the class content is important. As in, who is able to see what in a class is dependent on Encapsulation. Encapsulation is important to protect and to reduce simplicity in a class. Imagine, if the item (data, operation or class) is public to everyone, any changes on the public item (data, operation or class) will effect other's operation involving the item. Thus, Encapsulation is an approach that can lead us to Abstraction.

Both Abstraction and Encapsulation are important to achieve the concept of OO. We can reach Abstraction thru Encapsulation. This is a term that we have to bear in mind.


No comments:

Post a Comment