Abstraction

"Abstraction is the elimination of the irrelevant and the amplification of the essential"

  • Data Abstraction - primitive types, structure, files
  • Control Abstraction - functions, threads, process, control constructs
  • Object Abstraction - Data and its associated control/behavior

Abstraction Principles
Image Source: A. Taivalsaari. On the notion of inheritance. ACM Computing Surveys, 28(3):438-479, September 1996


Encapsulation

  • Encapsulation makes sure that abstraction is the only way to access the object
  • The purpose of encapsulation is to create abstractions and to protect them. The behavior of an object is abstracted by a specification.
  • An object, designed to meet a certain specification will maintain certain invariants. Encapsulation is the tool allowing to protect these invariants from destruction through improper use of the object. This is the reason for hiding the object's internal state from the outside and for making it accessible through methods only. (Another reason is to fully hide representation details, such that an object can represent state in the most appropriate way.)

When is encapsulation considered as broken:

  • Abstraction no longer works
  • Bypass abstraction and manipulate
  • Flaws in design - e.g. Top pointer public
  • Flaw/feature in language - exploited e.g. Viruses, buggy code using pointers

To avoid breakage of encapsulation: Ensure type safe computation - compile time and runtime ; Exception handling

<< Back to Tech Archives