SOLID Design Principles

A set of principles to help keep large object-oriented codebases understandable, maintainable, extensible and testable.

Created by Robert C Martin in 2000 paper Design Principles and Design Patterns.

https://web.archive.org/web/20150906155800/http:/www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf

Single Responsibility Principle (SRP)

  • A class should have one and only one responsibility.
  • All its methods and data should support that responsibility.
  • Makes classes more focused, easier to test and maintain.

Open/Closed Principle (OCP)

  • Software entities should be open for extension but closed for modification
  • Makes it easier to make changes to the system in the future
  • Avoids having to modify existing code
  • Use abstractions like inheritance or interfaces.

Liskov Substitution Principle (LSP)

  • Objects of a superclass should be replaceable with objects of a subclass.
  • Ensures that the program remains correct even after substitution.
  • Supports substituting objects of a derived class for objects of the base class.
  • Derived classes can extend the base class without changing behaviour.

Interface Segregation Principle (ISP)

  • Clients should not be forced to depend on interfaces they don’t use.
  • Avoids implementation of unused methods, resulting in better software design.
  • Promotes separation of concerns.
  • Encourage lots of smaller interfaces instead of few large interfaces.
  • Preferences composition over inheritance.

Dependency Inversion Principle (DIP)

  • High-level modules should not depend on low-level modules
  • Both should depend on abstractions
  • Promotes separation of concerns and makes the system more flexible and scalable
  • By following these principles, you can write software that is maintainable, scalable, and robust. SOLID provides a foundation for writing high-quality software that is easy to modify, test, and extend.
  • Examples: Inversion of Control (IOC), Dependency Injection.

By Sam

Drupal developer from Perth, Western Australia. I love programming, gaming, the Internet, growing vegetables and hiking.

Leave a comment

Your email address will not be published. Required fields are marked *