If someone asks me what Encapsulation is, how to I explain it? How
about Data Abstraction? I read a lot online but I want a very effective
answer to give.
richardsosborn@gmail.com - 07 Nov 2006 19:11 GMT
> If someone asks me what Encapsulation is, how to I explain it? How
> about Data Abstraction? I read a lot online but I want a very effective
> answer to give.
I'm not sure how much this will make sense. Encapsulation is "hiding"
data within an appropriate wrapper. This is what the Java Beans
specification was based on.
You have hidden members (class variables) and public accessors (methods
which
modify them). Once you have data you wish to protect access to, you
"encapsulate"
it in a proper bean or class. This is in place of simply dropping it
in a class and accessing
it however you like. It makes data more thread safe, I'm sure, among
other things.
Abstraction is grouping like things together. Often this is moving
frequently re-used
methods to a common "base class". For instance, you have functions you
keep using
over and over in a group of database classes. You might move them into
a top level,
"base class", you inherit. This keeps you from writing them over and
over again. Also
there's one place you change things in them.
I guess an example might be adding furniture to houses on a city block.
Do you place the
furniture within new houses and control access within them? Or do you
add one house that will showcase frequently-used items?
Manish Pandit - 07 Nov 2006 19:16 GMT
> If someone asks me what Encapsulation is, how to I explain it? How
> about Data Abstraction? I read a lot online but I want a very effective
> answer to give.
Encapsulation is combining the data, and the operations that work on
that data in a single unit.
Data Abstraction is being able to group smaller units of data into a
larger, logical unit that can be operated without the knowledge of
underlying components. For example, abstracting a Person data structure
out of 3 strings representing first, last, middle names, and an integer
representing age.
-cheers,
Manish
RedGrittyBrick - 07 Nov 2006 22:39 GMT
> If someone asks me what Encapsulation is, how to I explain it?
Wikipedia has some useful definitions of these and related concepts.
http://en.wikipedia.org/wiki/Information_hiding
> How
> about Data Abstraction?
http://en.wikipedia.org/wiki/Data_abstraction
amanda - 07 Nov 2006 23:43 GMT
Thank you all.
> If someone asks me what Encapsulation is, how to I explain it? How
> about Data Abstraction? I read a lot online but I want a very effective
> answer to give.