Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance or condition?

I've heard people saying that good design involves using inheritance instead of littering your code with if block. In what situation should we use inheritance, and when condition block is just fine?

like image 966
Hao Wooi Lim Avatar asked Sep 26 '26 11:09

Hao Wooi Lim


1 Answers

One refactoring like this is called Replace Conditional With Polymorphism.

We actually favor composition over inheritance, but ... it's really too broad of a topic to discuss here, however the book is worth a read and can get you started.

like image 116
Matt Hinze Avatar answered Sep 28 '26 21:09

Matt Hinze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!