Most of the books don't really clearly differentiate between Encapsulation, abstraction and Data Hiding and most of the time people treat these terms as synonyms.
When we ask people whts encapsulation ... the answer given is "Code is written in such a manner so that it acts as a capsule. And just like a capsule where we dont know whts inside it similarly we have code and we use it without knowing worrying about whts inside."
Now if we carefully analyse then above definition is mixture of all three terms and its not just encapsulation as is being told.
Data Hiding clearly means we need to hide data but then its our choice wht we need to hide and expose and thats where abstraction comes into picture.
Abstraction refers to deciding what are necessary details which we need to include in our code and expose[just like creating an ADT where mandatory operations are exposed but implementation is hidden]. But the implementation of those details needs to be hidden.
Now encapsulation provides us a placeholder [i.e a set of variables and operations] which is ultimately needed to implement Data Hiding and Abstraction.
Showing posts with label OOPS. Show all posts
Showing posts with label OOPS. Show all posts
Sunday, July 20, 2008
Subscribe to:
Posts (Atom)