Abstraction in Java

Abstraction can be defined as the process of hiding the unwanted details and exposing only the essential features of a particular object or concept. The concept of abstraction is used by classes and lists of attributes are defined in them like cost, size and weight, and methods that operate on their attributes. Abstraction is also achieved through composition.

For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.



Abstraction has three advantages:
 

  1. By using abstraction, we can separate the things that can be grouped to another type.
  2. Frequently changing properties and methods can be grouped to a separate type so that the main type need not under go changes. This adds strength to the OOAD principle -"Code should be open for Extension but closed for Modification".
  3. Simplifies the representation of the domain models.

 

Related Articles

post a comment