Monday, July 14, 2008

The truth of information hiding and encapsulation

As many people oftenly get confused in the jargon of these two closley interrelated terms(even me too ). Here i am jotting down what i could percieve about thses two gaints (ya they are!).
so at the very beginning i would like to tell you that there is not any ultimate defination (global agreement) of these terms. they have different meanings in different context. however i could clasify (in fact many experts also suggest the same thing) the two meanings in 1. Design perspective 2. Programming perspective


Design perspective:
lets first talk about the design principle.....feeling comfortable tll this point?!!
allright , one of the main motives of the design is to understand and control the complexity of the system (the problem). so we tend to redue the complexity by means of bunddling related things together.These bundles represnts a working unit(as elementry as possible) of the system. Now as these bundles are the actual c0nstructs of the system , so obviosuly they need to interact with each other(if they get enforced in a complete isolation then the system would become a simple wizzard in which there are discrete components , and no component knows about any other, each may perform its own job but it will be very difficult for others to take benifit of the job done, so not forming the system.). Now here we need to provide some mechanism by means of which one component may inetract with others so as to take benefits of the functioanlities in getting its own working done. Now this mechanism is called interafce. This interface will be the communication point of one bundle to another. so obviosly however a good design considers and tends to minimize these connections for achieving modularization. so this is all about encapsulation at design level. at this stage of design one can see the effect of change of one bundle on others, so one has to think in terms of protecting one part from the change (intented or accidental at the run time) of the other part..this introduces the great concept of information hiding. lets also have a glimpse of the dependency or interrelation of one to the other. Encapsulation itself is not an isolated concept , for example ..how to decide that which things are related and hence should be kept together in a spearate bundle (the encapsulated entity) , this problem gets solved by the concept of information hiding....it tells that, group only those elements together which correspond to a design decision to be hidden and prevent others by decreasing the connections to this group . so this shows the dependency of encapsulation on information hiding. information hiding also incorporates encapsulation , because by encapsulating we are hiding information from each other.


Programming perspective:
the fact that data and the methods to operate this data are shielded in a physical boundry(say a capsule and in object oriented programming language we call it an object) is called encapsulation.
however the concept of encapsulation at this level is to bring out the compartmentalization of the related things. this does not consider hiding something . at this point (As we havent introduced information hiding till now, by saying so i dont mean at all that these two things exist totally in isolation and dont even reject their concurrent existance, in fact they are oftenly concurrent as i discussed in the design perspective. so saying "at this point" i simply intend to comfortably illustrate the difference bw the two terms) there is not any comcern of hiding information objects (the capsule in the encapsulation analogy) from each other. Now programmer checks if there is some vital data(information) mishandling of which may cause dire(or even a little undesired too) consequences. so now he/she will tend to protect (by hiding from other part) that data by some mechanism (here comes access modifoers). And hence he by doing so successfully hidden the data from the outside world.
From the above discussion it would be clear that encapsulation doesnt guarantee information hiding (protection of data form accidental manipulation). A good object oriented programming incorporates both concepts in concurrent manner.

hope this was helpful to you...the article presented here is motivated by the perception made by the study of different articles found on the internet. this is an abstract of all thesis and lectures made by different experts..this doesnt reflect thinking of a single mind (just because thes two terms are too controversial...people still have much different opinions as i stated in the beggining)


this was a little effort , hope it helped...suggessions are invited loaded with queries

No comments: