Here are some violations in SOLID as examples

Violating Liskov’s substitution principle:

Inheritance is a purely “syntactic” relationship, whereas Liskov Substitution is also a “semantic” relationship.

Case 1:
How strengthened pre-condition breaks applications:

As you can see subclass object altered the baseclass price definition range for Pro Package. So this violates liskov’sSP and may crash app in later implementations.

Case 2:
How weakened post-condition breaks applications

One day if you extend/inherit from that baseclass to a “Free Package” subclass. It will alter the baseclass’ earlier definition and may break the app.

Example test usage:

I hope you get the point for Liskov’s Principle and how to avoid violating it.

I will continue adding more on solid’s other p’s in future.

Berkin Tatlısu


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