SOLID Design Principles Demystified

Let’s explore these SOLID principles in further detail.

Single Responsibility Principle

Open-Closed Principle

Liskov Substitution Principle

Rule1: The parameter types of a method in a subclass should match or be more abstract than those of the method in the superclass.

feed(Dog dog);
feed(Animal animal);
feed(HuskyDog dog);

Rule 2: In a subclass method, the return type must match or be a subtype of the return type in the method of the superclass.

Dog buyDog();
HuskyDog buyDog();
Animal buyDog();

Rule 3: A method in a subclass should not throw exceptions that the base method isn’t supposed to throw.

Rule 4: Subclasses shouldn’t strengthen preconditions.

Rule 5: Subclasses shouldn’t weaken post-conditions.

Rule 6: A superclass must preserve its invariants.

Rule 7: A subclass shouldn’t be able to modify a superclass’s private fields.

Interface Segregation Principle

Dependency Inversion Principle

References

--

--

--

“Walking on water and developing software from a specification are easy if both are frozen”

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Don’t get me wrong, I love Rust, but what’s wrong with it?

The rust logo

Install Scikit Learn on Apple Silicon M1

Leveraging ClipPath in Flutter

QuickLock| Your Personal Password Database just for YOU

A Few Handy Bash Aliases

How to Improve your Product with Limited Resources

HTML Tags! (Pt. 1)

There is power …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Neeraj Kushwaha

Neeraj Kushwaha

“Walking on water and developing software from a specification are easy if both are frozen”

More from Medium

Microservices Cross-Cutting Concerns Design Patterns

Microservices

Command and Query Responsibility Segregation (CQRS) Architecture

Monolithic vs Microservices architecture