Design Patterns Flashcards
What is a design pattern?
A design pattern is a way of reusing abstract knowledge about a problem and its solution. The pattern is a description of the problem and the essence of its solution.
(True or False) Design patterns should not be abstract. They need to be specific to be used in a variety of settings.
False! They actually need to be abstract to be applied in different settings.
What, in particular, are patterns?
Patterns (and pattern languages) are ways to describe bes praticies, good designes, and capture experience in a way that is possible for other to reuse this experience.
What are pattern elements?
- Name
- Problem description
- Solution description (not an actual design byt a template for a solution that can be instantiated in different ways)
- Consequences (the rults and trade-offs of applying the pattern.
What is the Observer Pattern?
The Observer pattern is a behavioral design pattern that establishes a one-to-many relationship between a subject and its observers, allowing multiple observers to automatically receive updates when the subject’s state changes. It promotes loose coupling, enabling observers to react to changes without tightly binding them to the subject.
What is pub-sub?
Pub sub is a subscribing system. It can also bee seen as real-time updates from the source to the application. This pairs most with the observer pattern.
What are the design pattern classes?
- Creational design patterns (dealing with class instantiation and object creation, effective inheritance, object delegation)
- Structural design patterns (defines inheritance to compose interfaces, construction of objects to obtain new functionality)
- Behavioral Design Patterns (explores class and object communication, interaction between objects)
(Creational Design Patterns) What is Abstract Factory?
Creates an instance of several families of classes.
(Creational Design Patterns) What is Builder?
Separates object construction from its representation.
(Creational Design Patterns) What is Factory Method?
Creates an instance of several derived classes
(Creational Design Patterns) What is Object Pool?
Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. (Library pre-creates instances of books for checkout)
(Creational Design Patterns) What is Prototype?
A fully initialized instance to be copied or cloned. This helps us to see what kind of edits we want. When we decide, we create a copy and then edit that.
(Creational Design Patterns) What is Singleton?
A class of which only a single instance can exist.
(Creational Design Patterns) What is Adapter?
Match interfaces of different classes. We make two things work together like an adapter. An adaptor creates an intermediary abstraction that translates, or maps, the old component to the new system.
(Creational Design Patterns) What is Decorator?
Add responsibilities to objects dynamically. (You add functionality to existing objects like scroll bars)