Week 15 - Compound Design Patterns
Compound Design Pattern¶
Classification¶
- Compound: Multiple design patterns working together to solve a common problem.
Pattern Definition¶
- Definition: Multiple smaller design patterns working together to solve a common problem. It is only a compound design pattern if it has been used to solve multiple problems, not just because it uses multiple design patterns.
Representations¶
Mermaid Graph - MVC Pattern¶
UML¶
- Combination of:
- Composite: View
- Strategy: Controller
- Observer: Model
MVC Usage¶
- View object is responsible for user input and output/presentation.
- The controller object implements the logic for the allowable transactions that can be performed on the model.
- The model object encapsulates the fine-grained business logic and data then notifies view/controller of updates.
MVC Sequence Diagram¶
1 2 3 4 5 6 7 8 |
|
Real World Usages¶
- ASP.Net MVC
- Django
- Magento
- Spring
Java Code Example¶
Main Take-Aways from the textbook¶
- The Model View Controller (MVC) Pattern is a compound pattern consisting of the Observer, Strategy, and Composite Patterns.
- The model makes use of the Observer Pattern so that it can keep observers updated yet stay decoupled from them.
- The controller is the Strategy for the view. The view can use different implementations of the controller to get different behavior.
- The view uses the Composite Pattern to implement the user interface, which usually consists of nested components like panels, frames, and buttons.
- These patterns work together to decouple the three players in the MVC model, which keeps designs clear and flexible.
- The Adapter Pattern can be used to adapt a new model to an existing view and controller.
- MVC has been adapted to the web.
- There are many web MVC frameworks with various adaptations of the MVC pattern to fit the client/server application structure.
Main OOP Principles of State Pattern¶
- All principles that apply to Strategy, Composite, and Observer Design Patterns.
- Loosely Coupled: Separation of concerns, the controller decouples the view from the model and vice versa.