Object Oriented Design Principles - RJAE5/2143-OOP GitHub Wiki
Object-Oriented Design Principles
The Object-Oriented Design (OOD) principles provide guidelines and best practices for designing software in an object-oriented way, emphasizing modularity, maintainability, and reusability. These principles aim to make systems more flexible and easier to manage. The first 5 major OOD principles are concepts of how OOP generally works using while the latter 5 are known as the SOLID Principles and subsequently will be discussed in their own page.
- Encapsulation
- Abstraction
- The concept of reducing complexity by limiting unnecessary information to the surface level user
- Inheritance
- The functionality of carrying over attributes and methods from one class to another and adding onto them
- Use when the class exhibits the "IS-A" relationship:
A car IS-A vehicle.meaning a classCarwould inherit from a classVehicle.
- Composition
- The functionality of using one or more user-defined types as the building block(s) of another class/struct
- Use when the class exhibits the "HAS-A" relationship:
A car HAS-A enginemeaning anEngineclass would need to be used in aCarclass.
- Polymorphism
- The concept that allows objects of different classes to be treated as objects of a common base class.
- It also allows methods to behave differently based on the object’s actual class.
- This is typically achieved through method overriding (runtime polymorphism) and method overloading (compile-time polymorphism).