Skip to main content

Posts

Behavioral Patterns in TypeScript

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
Recent posts

Structural patterns in TypeScript

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

Creational patterns in TypeScript

How to create instances of classes? Easy task, you may think, but it is not always. Creational patterns give us solutions to everyday situations where the creation of objects is not so easy. Sometimes you are faced with constructing complex objects or need to build them in a specific way. In other situations, you have a bunch of related classes and want to instantiate one of them based on runtime conditions. You may even have problems guaranteeing the uniqueness of an object or, on the contrary, want several almost identical copies. Picture  C Dustin  at  Unsplash This article will show how to solve these situations with four creational 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 Singleton Ensures that a class has only one instance around the application. The problem Some classes, like

Evolution of data models from primitive to clean entities in TypeScript

Data is the raw material of our programs. We must pay attention to its definition, cohesion and correctness . Often we find information that is scattered, redundant, or missing. This leads us to dirty and error-prone developments. Bad programmers care about the code. The good ones care about data structures and their relationships. Linus Torvalds Some solutions are unnecessarily complex. Other times they are applied out of place. I present to you a path of evolution so that little by little you can shape your business model. And most importantly, write maintainable programs in clean Typescript . 🎒 Prerequisites To complete this tutorial, you will need: Be aware of clean code naming rules. Know techniques for writing simple functions . 0️⃣ Primitive obsession This scenario takes its name from the fact that we are using primitive types to represent our data. Very common at the beginning of a developer's career. But, as we will see, it is not the best solution.