Abstraction, Encapsulation & Information Hiding
Abstraction: reasoning about the essential properties of an object, ignoring unimportant details.
- Extracts the essential details about an item, or a group of items, while ignoring the inessential details.
- In software development manages complexity by providing an interface to a module.
- Examine a complex problem.
- Distinguish between high- and low-level information.
- Extract high level information.
- Solve less complex problem.
- Apple Corer
- No abstraction; must understand process to make it work.
- Completely abstract interface.
- Input: food to be headed and setting.
- Output: hot food.
- Would be convenient to have an abstract interface.
- In reality the cook must understand the process in detail.
- Sink/ Tap
- Completely abstract.
- Input: turn tap.
- Output: water.
Order by increasing level of abstraction:
- Apple corer.
- Sink/ Tap.
Encapsulation refers to building a capsule, in the case a conceptual barrier, around some collection of things.
- Enclosing one or more items within a (physical or logical) container.
- Although often used as a method of disallowing access to or knowledge of internal structures of an implementation, does not in itself imply any sort of information hiding or protection.
- The process of hiding the implementation details of an object.
- It is a result of encapsulation or abstraction/ how they are achieved.
- Abstraction, information hiding, and encapsulation are very different, but highly-related, concepts.
- One could argue that abstraction is a technique that help us identify which specific information should be visible, and which information should be hidden.
- Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible.
- If encapsulation was the same thing as information hiding, then one might make the argument that everything that was encapsulated was also hidden– This is not obviously not true.