Download presentation
Presentation is loading. Please wait.
1
MVC Nick Lopez Duplication of course material for any commercial purpose without the explicit written permission of the professor is prohibited.
2
Design Patterns so far Simple problems regarding class interactions – Patterns so far involve few classes Are there larger problems that patterns can also support?
3
MVC Model View Controller Divides an application in 3 parts – Model – Views – Controller
4
MVC Provides a mechanism to propagate updates Guarantees consistency between info in the model and the what is presented in views The observer pattern is key
5
Motivation Allows for definition of highly cohesive models Emphasizes business logic over user interface Minimizes impact of changes when the interface evolves
6
Motivation Allows for definition of multiple views over the same model New views can be added without changes to the other components The model can be reused for other interfaces
7
Model Encapsulates the functionality of the application Registers observers Notifies observers of changes in the model Collaborates with views and controllers: – The controller can invoke methods from the model to make changes – The views and controllers get access to data for update
8
Model Application services Get data Notify changes Observer Update *
9
Model Application services Get data Notify changes Observer Update * ViewController
10
View Displays info to the user – Contains an update service activated when the model notifies changes Collaborates with model and controllers: – Obtains data from model – Can provide controllers with data visualizationservices
11
Controllers Receives input from the user Translates user events to service invocations in the model Collaborates with model and views: – The controller can also react to changes in the model (also can behave as a view)
12
Model Application services Get data Notify changes Observer Update * View Controller Update Display information Update Manage events
13
Exercise Does the number trains design implement MVC? Where is the model, views and controllers? – Make changes if necessary to make them explicit
14
Exercise Make changes to include a new view and a new controller Build a sequence diagram showing how views are registered Build a sequence diagram showing – an event from the user (adding a track) from one controller
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.