The Memento Pattern

What is a Memento Pattern? The Memento Pattern helps return an object to one of its previous states; for instance, if the user requests an “undo” operation. Source What problems does it solve? The Memento Pattern helps solve following problems: Undo/Redo Functionality: Memento allows you to capture an object’s state at a specific point in time and store it externally. This enables you to implement undo/redo functionality by restoring the object to its previous state....

March 22, 2024 · 2 min · Dmytro Chumakov

The Interpreter Pattern

What is an Interpreter Pattern? The Interpreter Pattern helps implement a simple language and defines a class based representation for its grammar along with an interpreter to interpret its sentences. Source What problems does it solve? The Interpreter Pattern helps solve following problems: Language Interpretation: When you have a language or syntax that needs to be interpreted, such as mathematical expressions, regular expressions, or domain-specific languages (DSLs), the Interpreter Pattern helps in implementing the logic to interpret and execute these expressions....

March 18, 2024 · 2 min · Dmytro Chumakov

The Flyweight Pattern

What is a Flyweight Pattern? The Flyweight Pattern refers to an object that minimizes memory usage by sharing some of its data with other similar objects. Source What problems does it solve? The Flyweight Pattern helps solve following problems: Large Memory Footprint: When dealing with a large number of objects, especially if these objects share a significant amount of common state, traditional object creation can lead to excessive memory consumption. The Flyweight Pattern reduces memory usage by sharing this common state among multiple objects....

March 17, 2024 · 2 min · Dmytro Chumakov

The Chain Of Responsibility Pattern

What is a Chain Of Responsibility Pattern? The Chain Of Responsibility Pattern helps create a chain of objects to examine requests. Each object in turn examines a request and either handles it or passes onto the next object in the chain. Source What problems does it solve? The Chain Of Responsibility Pattern (CoR) helps solve following problems: Dynamic Request Handling: It enables dynamic assignment of responsibilities at runtime. Handlers can be added, removed, or reordered without affecting the client’s code....

March 15, 2024 · 2 min · Dmytro Chumakov

The State Pattern

What is a State Pattern? The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class. Source What problems does it solve? Complex conditional logic: When an object’s behavior depends on its internal state, it often leads to complex conditional statements. The State pattern simplifies this by encapsulating each state and its behavior in separate classes, making the code more readable and maintainable....

March 10, 2024 · 2 min · Dmytro Chumakov