Design Patterns
Design Patterns
Model – View – Controller
Model – View – Controller
Copyright © 2001 DeLorme
28 November 2001
History
History
A framework pattern for reusable applications.
A framework pattern for reusable applications.
Depends on the Observer pattern.
Depends on the Observer pattern.
First developed by Xerox PARC for Smalltalk-80.
First developed by Xerox PARC for Smalltalk-80.
Used by the Application Kit system in NeXTstep.
Used by the Application Kit system in NeXTstep.
Used by the Cocoa APIs for Apple’s OS X.
Used by the Cocoa APIs for Apple’s OS X.
Recommended structural framework pattern in
Recommended structural framework pattern in
J2EE.
J2EE.
I have used this pattern for nearly ten years.
I have used this pattern for nearly ten years.
Copyright © 2001 DeLorme
28 November 2001
Observer Pattern
Observer Pattern
Defines a one-to-many dependency
Defines a one-to-many dependency
between objects so that when one object
between objects so that when one object
changes state, all its dependents are
changes state, all its dependents are
notified and updated automatically.
notified and updated automatically.
Used to decouple the subject from the
Used to decouple the subject from the
observer, since the subject needs little
observer, since the subject needs little
information to notify the observer.
information to notify the observer.
Can result in excessive notifications.
Can result in excessive notifications.
Copyright © 2001 DeLorme
28 November 2001
Observer Class Diagram
Observer Class Diagram
Observable
+addObserver(Observer)
+deleteObserver(Observer)
+notifyObservers(Object)
#hasChanged() : boolean
#setChanged()
Observer
+update(Observable,
Object)
AccountView
+update(Observable,
Object)
BankAccount
+widthdraw(double) : long
+deposit(double) : long
+getBalance() : double
SummaryView
+update(Observable,
Object)
Copyright © 2001 DeLorme
28 November 2001
Transactions Happen!
Transactions Happen!
Controller BankAccount AccountView SummaryView
deposit()
setChanged()
notifyObservers()
update()
update()
getBalance()
getBalance()