Wednesday, May 11, 2011

Encapsulation and data Abstraction

Abstraction Revolves around identifying the Physical and Logical (incl of 
Semi Physical) classes that are present in a system. 
Encapsulation Revolves around Saying this specific class that is identified 
during abstraction can be given to the user like this.... 

If I have said that I am going for a Student information system. The One who 
says you that a class called Student is required is Abstraction. The class 
student should not know how to update his marks is what is 
specified/implemented through the Encapsulation. Note that the rule which I 
mentioned above is the result of your understanding of the 
system(Abstraction). So the baseline is your Data Abstraction is a bird 
view of the total system. The things which you model are specified at 
abstraction level only.... It is the starting point for your Building of a 
System. 

As a Developer we decide that this specific user should understand the 
system upto this level only... for instance the Student information System 
assumes that the student can only see his marks he can not edit it. So the 
student view of the system is simplified to the user that is student. 
Better example is Your Bike. You know about your bike to an extent that is 
to drive, fill petrol and so on. For you it is not reqd to know how to 
Repair if it stuck in between. So the bike is offering you an interface 
through which you can work with it without bothering what is happening 
inside...Same is the case with Student. The System is allowing him to see 
his marks without bothering him to understand what a Teacher is doing... 
Sahil ofcourse Meant this... 

So A Perfect System that is modeled carefully will give the user a role 
based access in which the users will be offered an interface to perform the 
action without knowing the internal stuff. Abstraction is Preceedes 
Encapsulation in giving the user this kind of a Behaviour... 

Finally: these definitions are very specific to Me and Me only... But 
whatever some one says that can be boiled down to this points. 
Abstraction : Understanding and hmmmmmmmmmm... there are many 
Data Abstarction : 
1. Understanding of a System. 
2. Collection of Sub Systems to form a SuperSystem. 
You Call a Car as A "CAR" not " the One with a 4 wheels and 
blab la" 
Encapsulation: 
1. Grouping up the Data / Hiding the Data 
2. After identifying the classes one should know which 
behaviour should be exposed to whom??? Answer is encapsulation. 

So please never get confused with the definition (what is it?) and 
implication(How does it matter/ what is that it do???)... 

OOPS!! I am Tired... I'll Rest Here... still some more doubts on OOP terms 
... Never mind to shoot me bak.... 

No comments:

Post a Comment