Notes - Imperative Programming TT23, Design patterns
Patterns
Adapter
Give the sales pitch for the “Adapter” design pattern.
- Name: Adapter
- Problem: You want to use an existing type, but it doesn’t impleemnt the required interface.
- Solution:
- Target: Interface we wish to provide
- Client: The code that expects the required interface
- Adaptee: The type we wish to present in a different interface
- Adapter: The “wrapped” type, with the required adapter
Observer
Give the sales pitch for the “Observer” design pattern.
- Name: Observer
- Problem: You have a many-to-one relationship and want to reduce tight coupling
- Solution:
- Observer: Interface with a method to be notified when changes occur
- Subject: A class for recording observers and notifying them of changes
- Concrete Subject: A class that the observers are interested in and that notifies observers as required
- Concrete Observer: A concrete implementation of the observer, which update when they are notified.
Model-View-Controller
Describe the three aspects of the model-view-controller pattern.
- The model: The internal description of the data relevant to the application.
- The view: The code responsible for presentation of data to users.
- The controller: Processes user input, and updates the model as needed.