-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
TypeScript 5 Design Patterns and Best Practices - Second Edition
By :
Object-Oriented Programming (OOP) principles and design patterns encourage modeling real-world entities using classes. While the benefits of OOP are well recognized, it often leads to an overabundance of classes. This can create complications in your code structure.
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. In the next section, we’ll examine an analogy to emphasize this issue at hand.
When you attempt to emulate a system using classical OOP techniques such as inheritance and encapsulation, you often end up carrying over entire class hierarchies. This is exemplified by the banana, monkey, jungle problem. For instance, if you want to use a Banana object, you might need to import a Jungle object that contains a Monkey instance, which exposes the getBanana() method:
new Jungle().getAnimalByType("...