Five Basic Principles of Object Oriented Programming and Design

In the early 2000s Robert C. Martin, commonly known as “Uncle Bob”, came up with a list of 11 principles of good Object Oriented Design (OOD).

Jeff Prado
2 min readAug 4, 2021

The first five principles are principles of what makes good class design. These five principles are what have become known by the acronym “SOLID” which Michael Feathers helped coin. These principles when learned and implemented correctly help developers create and maintain a codebase that is strong but flexible to grow and change with minimal difficulty.

Single responsibility principle

The notion that an object should only have a single responsibility.
Store data — Present graph — Web queries
NOT everything in the main.
NOT queries from view.

Open / closed principle

The notion that “software entities… should be open for extension, but closed for modification”.
DO NOT edit the base code of a module
Usually with abstract classes or interfaces.

Liskov substitution principle

The notion that “objects of a program should be replaceable by instances of its subtypes without altering the correct operation of the program.” See also design by contract.
Children must continue to behave like their parents.
ONLY inherit to add behavior not to modify existing.

Interface segregation principle

The notion that “many specific client interfaces are better than a general-purpose interface.”
DO NOT give more information than necessary.
Separate the interfaces as much as possible.

Dependency inversion principle

The notion that one should “depend on abstractions, not depend on implementations.” Dependency Injection is one of the methods that follow this principle.
Reduce dependencies between modules.
Someone must create objects and give them to the modules where they work. DO NOT create objects where they are handled.

In conclusion, SOLID are guiding principles to consider but THEY ARE NOT RULES. Sometimes by applying them you could end with thousands of code lines that can be difficult to maintain. So, do not sacrifice functionality to apply all the principles.✌

--

--