Software design principle explained with simple example

Software design principle consists a set of guidelines invented by Robert C.Martin to avoid bad software design. These guidelines consists of five design principles for object oriented software development. These design principles are:

Together these are called SOLID design principles.

Single Responsibility Principle

This principle states that “every class should have one and only one responsibility“. If a class has more than one job to do then its best to break into multiple smaller classes. This will allow software design to be modulated and enhance maintainability of the software. Don’t try to create a big class which does all the job. It always backfires.

Open/Closed Principle

This principle states that every class should be “Open for extension but closed for modification“. All member function should be private and only required getters and setters functions should be provided. This principle enforces the use of Abstract classes for defining the behaviour while multiple inherited concrete classes provides the implementation.

Liskov Substitution Principle

This principle states that “derived class objects should be completely replaceable for their base classes“. This principle ensures that any derived class extending the base class will not change their behaviour. This principle enforces to create loosely coupled modules and avoid unnecessary coupling.

Interface Segregation Principle

This principle states that “many client specific interfaces are better than one generic interface“. This principle enforces to implement only usable methods which will reduce coupling between modules. This principle enforces to avoid writing useless methods. Thus increasing the maintainability of code.

Dependency Inversion Principle

This principle states that “High-level modules should not depend on low-level modules. Both should depend on abstractions And Abstractions should not depend on details. Details should depend on abstractions“. This principle enforces to decouple high level modules from low level modules resulting into more reusable code.

These design principles are defined to help in designing the software. Ask relevant question about these aspects which will show noticeable difference in software design.

Always think before jumping to write code.

Leave a Reply

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