120 likes | 208 Views
Model-View-Controller Related Patterns. Kirk Scott. This is an introductory unit. These are the units/chapters belonging to this section of the course: Unit 30, Observer, book chapter 9 Unit 31, Memento, book chapter 19.
E N D
Model-View-Controller Related Patterns Kirk Scott
This is an introductory unit. • These are the units/chapters belonging to this section of the course: • Unit 30, Observer, book chapter 9 • Unit 31, Memento, book chapter 19
Although there are only two units, this is a significant set of patterns • Memento is pretty much a sideshow • The implementation of Observer in the Java API is the basis for the development of fully model-view-controller designs • The second homework assignment addresses this
Observer • Book definition: The intent of the Observer pattern is to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified so that they can react to the change.
Comment mode on: • Think back to the topics of listeners and multicasting in CS 202 • Not only can code be written to respond to external events • Code can also be written so that objects respond to changes in other objects within an application
Memento • Book definition: • The intent of the Memento pattern is to provide storage and restoration of an object’s state • Comment mode on: • This turns out to be as straightforward as the definition seems to imply
In Summary • In a sense, the observer is the heart of the MVC pattern • An observer is that part of an application that makes it responsive to events, whether internal or ultimately driven by things that happen externally
At first glance, you may wonder why I have put the memento pattern with observer • My idea is that the memento is based on the concept of saving the model and restoring the model and view for an application • You don’t have to use memento with observer—but memento deals with some of the same application components as observer