S08 Model View Controller
S08 Model View Controller
Model-View-Controller
View
Model
Controller
MVC FLOW
In theory…
Pattern of behavior in response to inputs (controller) are independent of visual
geometry (view)
Controller contacts view to interpret what input events should mean in the context
of the view
In practice…
View and controller are so intertwined that they almost always occur in matched
pairs (ex: command line interface)
Many architectures combine the two
MVC FLOW IN PRACTICE
View
Model
Controller
HOMEWORKS
HW8 – fine to keep view and controller together
View
Model
Controller
PUSH VS. PULL ARCHITECTURE
Push architecture
As soon as the model changes, it notifies all of the
views
Pull architecture
When a view needs to be updated, it asks the model
for new data
PUSH VS. PULL ARCHITECTURE
PUSH VS. PULL ARCHITECTURE
Advantages for push
Guaranteed to have latest data in case something goes
wrong later on
View
Conveys information to cars and pedestrians in a specific
direction
Controller
Aware of model’s current direction
Triggers methods to notify model that state should change
TRAFFIC SIGNAL CODE
Model
TrafficModel – keeps track of which lights should be on and off
View
CarLight – shows relevant state of TrafficModel to cars
PedestrianLight – shows relevant state of TrafficModel to pedestrians
Controller
PedestrianButton – notifies TrafficModel that there is a pedestrian
waiting
CarDetector – notifies TrafficModel that there is a car waiting
LightSwitch – enables or disables the light
Timer – regulates time in some way, possibly to skip cycles
HW8 OVERVIEW
Apply your generic graph & Dijkstra’s to campus
map data
Given a list of buildings and walking paths
Produce routes from one building to another on
the walking paths
HW8 DATA FORMAT
List of buildings (abbreviation, name, loc in pixels)
BAG Bagley Hall (East Entrance) 1914.5103,1708.8816
BGR By George 1671.5499,1258.4333
List of paths (endpoint 1, endpoint 2, dist in feet)
1903.7201,1952.4322
1906.1864,1939.0633: 26.583482327919597
1897.9472,1960.0194: 20.597253035175832
1915.7143,1956.5: 26.68364745009741
2337.0143,806.8278
2346.3446,817.55768: 29.685363221542797
2321.6193,788.16714: 49.5110360968527
2316.4876,813.59229: 44.65826043418031
(0,0) is in the upper left
MVC IN HW8
Model stores graph, performs Dijkstra’s