Liskov Substitution Principle

Prashant Jha
Mar 27, 2023

--

Liskov Substitution principle states “Derived class must be substitute of parent class.” In JS method of child component must be exact replica of method of parent component.

The method in child component should be exact number of arguments, exact types of arguments and exact return type as parent (types referring to typescript).

Simply put, you should be able to replace a parent component with a child component that behaves in the same way. This makes the code more flexible and easier to scale.

Here as we can see, we are using BtnTwo in BtnOne component and in both component print method is same only. That method can be replaced in both component with each other. So, we can write the same code as below :-

In less number of lines where print method is interchangeable between BtnOne and BtnTwo. Which fulfills the Liskov Substitution principle.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Prashant Jha
Prashant Jha

Written by Prashant Jha

interested in Code, Books, Philosophy, Poems

No responses yet

Write a response