Grasp SOLID Principles in one minute

Rachanee Saengkrajai
3 min readMay 25, 2020

SOLID Principles is a coding standard that all developers should have a clear concept for developing software in a proper way to avoid bad design.

S Single-responsibility principle
O Open-closed principle
L Liskov substitution principle
I Interface segregation principle
D Dependency Inversion Principle

Single-responsibility principle

A class or method should have only one responsibility.

Meaning that A class or method should have one and only one reason to change.

Split code to handle file uploading to another class.
Split methods to have single-responsibility.

Open-closed principle

Objects or entities should be open for extension, but closed for modification.

This simply means that a class should be easily extendable without modifying the class itself. The virtual and override keywords allow you to do so.

Make method SaveUploadedFile be virtual to open for extension.

Liskov substitution principle

Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.

All this is stating is that every subclass/derived class should be substitutable for their base/parent class.

Override method CreatePost to make the MentionPost be substitutable by Post.

Interface segregation principle

A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.

Split interfaces until it has only the necessary methods that implementer needs.

Split interfaces so that the implementer is not forced to implement method DeletePost if it does not use.

Dependency Inversion Principle

Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.

This principle allows loosely-couple of components and is the principle of the Dependency Injection technique.

PostHandler should depend on the IPost interface instead of the concrete class MentionPost to decouple dependencies.

--

--