Skip to content

4 Major Concepts Of OOP Summarised

etbf edited this page Mar 12, 2021 · 3 revisions

Abstraction aims to hide code complexity and only show users the information that they need to know. For example, if you want to drive a car, you don’t need to know about how the car works for it to move.

  • Hides the underlying complexity of data
  • Helps avoid repeated codes
  • Presents only the signature of inner functions
  • Gives flexibility to change the utilization of the abstract behavior
  • Abstract classes can perform partial abstraction
  • Interfaces can perform total abstraction

Encapsulation allows us to protect the data stored in a class from system-wide access. It binds data and its related methods together within a class.

  • Restricts direct access to fields of a class.
  • Fields are set to private
  • Getter methods return the field
  • Setter methods allow us to change the value of the field

Polymorphism refers to the ability to perform a certain action in different ways. In Java, polymorphism can take two forms: method overloading and method overriding.

  • Different methods of the same name with different method signatures can be called.
  • All Java objects can be considered polymorphic (they are at least of their own type and instances of the Object class).
  • Method overloading is an example of static polymorphism.
  • Method overriding is an example of dynamic polymorphism.

Inheritance makes it possible to create a child class that inherits the fields and methods of the parent class so that it can override the values and methods of the parent class and add new data and functionality to its parent.

  • A child class can extend a parent class by inheriting its features.
  • Utilizes the DRY (Don’t Repeat Yourself) programming principle.
  • Enhances code reusability.
  • Multilevel inheritance is allowed in Java (a child class can have its own child class as well).
  • Multiple inheritances are not allowed in Java (a class can’t extend more than one class).