posted 19 years ago
Abstraction is about leaving out details that don't matter in the current conversation so you can focus on other details that do matter. For example a method that takes a List parameter cares about the behavior that is promised by the List interface, but doesn't care whether it's an ArrayList or LinkedList or some other implementation. So we call List an abstraction and ArrayList a concrete example. Or I might say I have a program that is a socket server without going into all the details of ports, socket objects, IO exceptions, message payloads and so on.
What matters and what you can leave out depends on the conversation and the audience. If I explain my program to somebody who must write their first socket program as a client to my server, I might give them many more details.
Encapsulation has about as many definitions as there are OO programmers. I'd say it's some mix of bringing together related code and data and hiding information about the details. Some of the big names in the business have said that encapsulation == information hiding, while others point out that not all information hiding leads to good encapsulation and not all encapsulation leads to good information hiding.
Any of that help? Raise new questions?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi