Chapter 6 - Design Patterns Flashcards
Design patterns
descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context
design for change
when designing a system we should also plan for inevitable changes.
Creational
patterns proposing flexible solutions for creating objects. They include Abstract Factory (6.2), Factory Method, Singleton (6.3), Builder (6.12), and Prototype.
Structural
patterns proposing flexible solutions for composing classes and objects. They include Proxy (6.4), Adapter (6.5), Facade (6.6), Decorator (6.7), Bridge, Composite, and Flyweight.
Behavioral
patterns proposing flexible solutions for interaction and division of responsibilities among classes and objects. They include Strategy (6.8), Observer (6.9), Template Method (6.10), Visitor (6.11), Chain of Responsibility, Command, Interpreter, Iterator (6.12), Mediator, Memento, and State.
Singleton
This design pattern ensures that a class, as the name suggests, has at most one instance
Factory
(1) creates and returns objects of a particular class; and (2) hides the type of these objects behind an interface
Proxy
advocates the use of an intermediary object, also known as a proxy, between a base object and its clients
stubs
facilitate remote communication.
Adapter
This pattern is recommended when we need to convert one class interface into another.
Facade
a class that offers a simplified interface to a complex system. The objective is to shield users from the need to understand the internal classes of this system.
Decorator
Instead of using inheritance, it employs composition to dynamically add these functionalities to base objects.
Strategy
aims to parameterize the algorithms used by a class, encapsulating a family of algorithms and making them interchangeable
Observer
defines a way to implement a one-to-many relationship between subject and observer objects. When the state of a subject changes, all its observers are notified.
Template Method
specifies how to implement the template of an algorithm in an abstract class, which we’ll call X, while deferring some steps or methods for implementation in the subclasses of X. In summary, a Template Method allows subclasses to customize an algorithm without changing its fundamental structure, which is defined in the base class
double dispatch
the types of the target object and one argument are used to determine the method that will be invoked. (only available in a few languages)
Visitor
This pattern provides a way to add an operation to a family of objects without modifying the classes themselves.
Designed to function effectively even in languages with single dispatching, such as Java.
Iterator
a design pattern that standardizes an interface for traversing a data structure
Builder
a design pattern that simplifies the instantiation of objects with several attributes, some of which may be optional
patternitis
an inflammation associated with the premature or excessive use of design patterns