DEV Community

Cover image for SOLID: The Liskov Substitution Principle (LSP) in C#

SOLID: The Liskov Substitution Principle (LSP) in C#

Aditya on December 19, 2024

Introduction The Liskov Substitution Principle (LSP) is a foundational concept in object-oriented design, introduced by Barbara Liskov i...
Collapse
 
tallesl profile image
Talles L • Edited

Not that I care, I think inheritance just ruins codebases anyway, but a nitpick: a square is a rectangle. The second code snippet (the solution) fails that check.

Collapse
 
extinctsion profile image
Aditya

Agreed. But dont you think inheritance makes our lives a bit easier? We have to write a bit less code and enjoy being lazy....

Collapse
 
tallesl profile image
Talles L

After many years of digesting many kinds of codebases, I'm definitely a "composition over inheritance" kind of person...

Sharing things by inheritance eventually bites you when you have to change a base behavior but just for some of the classes instead of all of them.

Collapse
 
the_patience_tester profile image
petergsimons

Good job explaining something relatively complex in such a nice and simple way, as someone who has interviewed a lot of developers throughout my career I can honestly say this is something people always struggle to articulate beyond reciting the "dictionary definition" during interviews

Collapse
 
extinctsion profile image
Aditya

Thanks! I hope you like this article. Follow for more such contents

Collapse
 
jangelodev profile image
João Angelo

Hi, thanks for sharing!

Collapse
 
extinctsion profile image
Aditya

I'm glad you liked it

Collapse
 
auyeungdavid_2847435260 profile image
David Au Yeung

Thanks for reminding!

Collapse
 
extinctsion profile image
Aditya

Thanks! if you liked the content pls give a thumbs up for upcoming articles

Collapse
 
riccardo-10 profile image
Riccardo richard_ekeopara_846

Very good article 👍

Collapse
 
extinctsion profile image
Aditya
Collapse
 
lurodriguez profile image
L Rodríguez

Very good example

Collapse
 
extinctsion profile image
Aditya

I'm glad that you liked it