Design Principle: SOLID Principles

Design Principle

SOLID principles are a collection of design principles used to make the implementation of software systems more readable, maintainable, flexible(for later changes), and easily understandable. SOLID Principles refer to a collection of five(5) individual principles, widely used in Object-Oriented Programming(OOP). The term “SOLID” is derived from the first letter of each of those 5 principles.

Design Principle: Interface Segregation Principle(ISP)

Design Principle

The Interface Segregation Principle says- We should create smaller and more specific interfaces, instead of having large monolithic interface with many methods. Each interface should only contain methods that are relevant to the purpose of the interface. Then classes can implement one or more of those interfaces are required. Also, a class should only implement the interface(s) which are required.

Design Principle: Liskov Substitution Principle(LSP)

Design Principle

Liskov Substitution Principle(LSP) says-Objects of superclass should be replaceable by the objects of a subclass, without affecting the correctness of the program. When subclass object replaces super class object, the result might not be exactly same, but rather it – should be consistent, has the same intended behavior, should not break any functionality.

Design Principle: Open/Closed Principle(OCP)

Design Principle

Open/Close Principle(OCP) says- Software entities(classes, modules, etc.), should be open for extension but closed for modification. It means that once a software entity is defined and implemented, we should not directly change it to add new functionality. Instead, we should extend it using inheritance or interfaces to accommodate new behavior or functionality.

Design Principle: Program to Interfaces, Not Implementations

Design Principle

The “Program to Interfaces, Not Implementations” principle is- Design your code to depend on interfaces, and avoid the dependency on concrete classes. The process is to define interfaces that specify required behavior. Classes then implement the interface and allow the system to extend and modify the implementation, without changing the dependent code.