
TypeScript 4 Design Patterns and Best Practices
By :

OOP principles and design patterns promote a type of programming where you try to model the real world using classes and entities. While the benefits of OOP are well recognized and understood, quite often OOP can lead to a proliferation of classes.
To explain what we mean, when you try emulating a system using classical OOP techniques such as inheritance and encapsulation, you inevitably have to carry over the whole hierarchy.
This leads to the banana, monkey, jungle problem. You want to use a banana
object but in order to get the banana
object you will have to import the Jungle
object that holds the monkey
instance that exposes the getBanana()
method:
new Jungle().getAnimalByType("Monkey").getBanana();
This example code indicates that the problem lies with how you structure your classes and how you utilize them in the code.
Practically this means that when OOP techniques are heavily utilized, the benefits of reusability and inheritance fade...