Model View Controller With Observer View Flashcards
Basic MVC roles
Model: Hold and manipulate data. Notifies view when changes occur.
View: Takes user input. Presents and visualizes data.
Controller: Receives user input. Converts input messages to the model.
How does the observer pattern fit into MVC?
Model becomes observable. View observes model. Controller has listeners that listen to things in the view.
View.
Implements observer interface.
update() called by Model
Model.
Inherits from Observable class.
Has observer.
addObserver(Observer o)
model.addObserver(view) usually done after model and view are created. Lets the model notify the view with setChanged() and notifyObservers()
How can the view be updated?
After notification, the view either pulls data via accessors, or the model pushes data.
Note: If pull used, view must store model as an instance variable.
How to push an update?
notifyObservers(Object arg)
Sends an object of our choice to all observers. In this case, the view doesn’t necessarily need access to the model.
Controller.
Intercepts events when buttons clicked, and tells model to change.
This indirectly causes observers like the view to be notified.
The view then gets the data one way or another.