Skip to main content

SOLID Principle

Single-responsiblity Principle

Open-closed Principle

Liskov Substitution Principle

Subclasses should be substitutable for their base classes.

Given that class B is a subclass of class A, we should be able to pass an instance of class B to any method that expects an instance of class A and the method should not give any weird output in that case.

So in terms of functionality, subclass B should be a superset of superclass A.


Although in math, Square is a special case of Rectangle, letting Square class inherit Rectangle class violates Liskov Substitution Principle.

Square cannot replace Rectangle as its width and height are set together.

Interface Segregation Principle

Dependency Inversion Principle