Software EngineeringObject-Oriented Programming (OOP)

Object-Oriented Programming (OOP)

Cheat sheet for 4 Pillars of OOP and SOLID Principles

Object-Oriented Programming (OOP) Cheat Sheet

Object-Oriented Programming (OOP) relies on key principles and practices that help make code easy to manage and flexible.

4 Pillars of OOP

The 4 pillars of OOP consist of:

  1. Encapsulation: Hiding the internal state of an object and forcing data access through methods (such as getters and setters) only, to prevent accidental modification of data.
  2. Abstraction: Hiding complex implementation details and exposing only the interfaces or functions necessary for usage.
  3. Inheritance: Creating a new class that inherits properties and methods from an existing class, allowing code reuse.
  4. Polymorphism: The ability of an object to be treated as an object of its parent class, allowing the same interface to be used for different data types.

SOLID Principles

SOLID consists of 5 design principles for OOP to create software that is easy to maintain and scale:

  • Single Responsibility Principle (SRP): A class should have only one responsibility or one reason to change.
  • Open-Closed Principle (OCP): A class should be open for extension but closed for modification.
  • Liskov Substitution Principle (LSP): Objects of a subclass should be able to replace objects of a superclass without causing the program to malfunction.
  • Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. Large interfaces should be separated into smaller and more specific interfaces.
  • Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions.

AI Knowledge Assistant

สวัสดีครับ! ผมคือ AI Assistant ประจำเว็บไซต์

คุณสามารถสอบถามข้อมูลด้าน Computer Science, Business, หรือ Finance ได้เลยครับ