To create understandable, readable, and testable code that many developers can collaboratively work on
Properties of OOP:
1. Abstraction:
aims to hide complexity from users and show them only relevant information
For an example, when you are driving a car, you don't need to know about the engines and the internal workings.
2. Encapsulation:
Helps with data security; allows you to protect the data stored in a class from system-wide access
3. Inheritance:
Makes it possible to create a child class that inherits the fields and methods of the parent class
The child class can override the values and methods of the parent class; it can also add new data and functionality to its parent
Parent class = superclass, base class
Child class = subclass, derived class
4. Polymorphism:
Refers to the ability to perform a certain action in different ways
In Java, there are two forms: method overloading and method overriding
Method overloading: happens when various methods with the same name are present in a class. They are differentiated by the number, order, or types of their parameters
Method overriding: occurs when a child class overrides a method of its parent
The Single Responsibility Principle
The Open-Closed Principle
The Liskov Substitution Principle
The Interface Segregation Principle
The Dependency Inversion Principle
The Single Responsibility Principle
A class should do one thing and therefore it should have only a single reason to change
Only one potential change in the software's specification should be able to affect the specification of the class
Adv1: When different teams work on the same project and edit the same class for different reasons, this could lead to incompatible modules. SRP prevents this.
Adv2: Makes version control easier. Fewer merge conflicts.
Object Oriented Programming, OOP
The purpose of OOP:
Properties of OOP:
1. Abstraction:
2. Encapsulation:
3. Inheritance:
4. Polymorphism:
Source