Design Patterns Flashcards
What are the three categories of design patterns (from Gang of Four)?
Creational
Structural
Behavioral
Role of Creational Design Patterns?
Abstract the instantiation
Make system independent of how objects are created, composed and represented
Role of Structural Design Patterns?
Compose classes/objects to form larger structures
Role of Behavioral Design Patterns?
Algorithms
Assignment of responsibilities between objects
What problems do the Observer Design Pattern seek to solve?
Maintaining consistency between related objects
Resolving dependency between two aspects
Want to notify other objects without making assumptions about the target objects.
Give a high level description of an Observer Design Pattern.
Two separate objects: Observable and Observer
Observable maintains a list of observers for itself
Detects changes and notifies all subscribed observers.
What is a Singleton Design Pattern?
A class which may only ever have a single instance that is globally accessible
Give a high level description of how a Singleton Design Pattern works.
Globally accessible getInstance()
function that returns the singleton, or creates one if it does not exist
What is the purpose of an Iterator function?
Iterate over a container/collection of objects without revealing how elements are stored
What problems does the Strategy Design Pattern solve?
Want to use multiple different algorithms (strategies) at different times while minimizing amount of code that needs to be rewritten
Role of Creational Design Patterns?
- Abstract the instantiation
- Make system independent of how objects are created, composed and represented
Role of Behavioral Design Patterns?
- Algorithms
- Assignment of responsibilities between objects
What problems do the Observer Design Pattern seek to solve?
- Maintaining consistency between related objects
- Resolving dependency between two aspects
- Want to notify other objects without making assumptions about the target objects.
Give a high level description of an Observer Design Pattern.
- Two separate objects: Observable and Observer
- Observable maintains a list of observers for itself
- Detects changes and notifies all subscribed observers.
What problems does the Strategy Design Pattern solve?
Want to use multiple different algorithms (strategies) at different times while minimizing amount of code that needs to be rewritten