How do objects behave? At runtime, their life is about instantiating, calling, and being part of processes bigger than themselves. It is a complex and critical matter involving our programs' flow control and data manipulation. Behavioral patterns guide us on how instances communicate with others. Well-designed applications end up with dozens of classes. Some are like legacy-sealed stones, while others seem living creatures evolving. Sometimes we must deal with complex subsystems or add complexity to a simple buddy. This article will show how to solve these situations with four behavioral patterns with examples in TypeScript . Let's dive in! 🎒 Prerequisites To complete this tutorial, you will need the following: A local development environment for TypeScript Basic knowledge of Object-Oriented Programming 🎖️ Strategy Decouples third-party libraries (or legacy code) from the application The problem class Logger { log(entry: LogEntry): string { const
How to compose objects? It's an excellent question; Thinking about composition is, first and foremost, the right way to relate classes. Structural patterns guide us on how and when to wrap some instances in others. Well-designed applications end up with dozens of classes. Some are like legacy-sealed stones, while others seem living creatures evolving. Sometimes we must deal with complex subsystems or add complexity to a simple buddy. This article will show how to solve these situations with four structural patterns with examples in TypeScript . Let's dive in! 🎒 Prerequisites To complete this tutorial, you will need the following: A local development environment for TypeScript Basic knowledge of Object-Oriented Programming 🔌 Adapter Decouples third-party libraries (or legacy code) from the application The problem