Design Patterns (Week 7, part #2) Flashcards
What are the separation of concerns in web computing?
HTML - structure / organisation of content
CSS - presentation
Javascript - functionally
What is ‘separation of concerns’?
1) A design principle for separating software code into distinct ‘sections’, such that each section addresses a separate concern.
2) A strategy for handling complexity
- -> Of the problem
- -> Of the solution e.g. software code
What can we reuse to connect views and data?
models and views
What are the different variations on the theme of Model-View-{Bridge}
1) Model View Controller (MVC)
2) Model View Adaptor (MVA)
3) Model View Presenter (MVP)
4) Model View ViewModel (MVVM)
Define the components of MVC
✨✨✨
Model - directly manages data, logic and rules. Expresses behaviour of problem domain
View - output representation of information
Controller - accepts input and converts it to commands for the model or view
What is MVVM?
✨✨✨
Model-View-ViewModel
ViewModel is an <strong>abstraction of the view, exposing public properties and commands.</strong>
The binder mediates communication between the view and the data binder
Draw an annotated diagram of MVC
See diagrams doc #3
Draw an annotated diagram for MVVM
See diagrams doc #4
In terms of MVC, if business logic gets complex, where do we put it?
In state
Explain the observer pattern in terms of the diagram #5
Screen = Presentation:
User sees the quantity they entered and the calculated total
–> Specific to the UI
–> Independent of Domain
Session state = Model Quantity stored in state Observer watches the quantity and pushes new total to interface --> Independent of UI --> Specific to the Domain
Record state = Data
What are the PROs of MVC?
✨✨✨
+ Multiple views
+ Synchronized views
+ Pluggable views and controllers
+ Exchangeable look and feel
What are the CONs of MVC? (5)
✨✨✨
- Complexity
- Can have lots of updates/notifications
- Links between controller and view
- Coupling of controller/view and model
- Mix of platform-dependent/independent code within controller and view (porting)
Compare MCV and MVP using two diagrams to illustrate the differences
See diagram doc #6
Explain the difference between MVC and MVP
✨✨✨
1) MVC is Model-View-Controller
<strong>view is stateless with not much logic.</strong>
<strong>Renders a representation of model(s)</strong> when called by controller or triggered by model.
<strong>Gets data directly from model.</strong>
2) MVP is Model-View-Presenter
<strong>view</strong> can be <strong>completely isolated from model</strong> and <strong>rendering data from presenter</strong>, or can be a MVC view, or somewhere in between (e.g. view separate from model)
Give diagram for MVP
See diagram doc #6 & #7