amanda said:
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?