Contents
Design Patterns - Why?
Model-View-Controller Pattern
MVC Observer Pattern
(Composite Pattern)
Nguyen Trung Lap Strategy Pattern
Hoa Sen University
MVC variants examples
Design Patterns - Why? Design Patterns - Why?
Designing OO software is hard Expert designers know not to solve every problem from
Designing reusable OO software – harder first principles
Experienced OO designers make good design They reuse solutions
New designers tend to fall back on non-OO techniques These patterns make OO designs more flexible, elegant,
used before and ultimately reusable
Experienced designers know something – what is it?
Model-View-Controller Pattern MVC – What Is the Problem?
MVC consists of three kinds of objects: The same enterprise data needs to be accessed when
– Model – the application object presented in different views: e.g. HTML, JFC/swing,
– View – UI (screen presentation) XML
– Controller – defines the way the UI reacts to user inputs
The same enterprise data needs to be updated through
different interactions
Supporting multiple types of views and interactions
MVC Structure
MVC – Solution
Separate core business model functionality from the
presentation and control logic that uses this functionality
Allows multiple views to share the same enterprise data
model
Makes supporting multiple clients easier to implement,
test, and maintain
MVC – Responsibilities MVC – Class Diagram
Model
– the model represents enterprise data and the business rules that
govern access to and updates of this data
View
– the view renders the contents of a model. It accesses enterprise
data through the model and specifies how that data should be
presented
Controller
– the controller translates interactions with the view into actions to
be performed by the model
MVC – Class Diagram MVC – Class Diagram (including interfaces)
Strategy Pattern
Observer Pattern
Observer Pattern
MVC – Class Diagram (including interfaces)
Class Diagram
controller
view
model
Observer Pattern Sequence
Observer Pattern
Diagram
Define a one-to-many dependency, all the dependents ??? : ConcreteSubject ob1 : ob2 :
ConcreterObserver ConcreterObserver
are notified and updated automatically notify( )
update( )
The interaction is known as publish-subscribe or
getState( )
for each
observer
update( )
subscribe-notify
getState( )
Avoiding observer-specific update protocol: pull model
vs. push model
Other consequences and open issues
Strategy Pattern – Class
Composite Pattern
Diagram
View can be nested
Described by the Composite design pattern seen in the
lecture
Strategy Pattern Three Tier Model
Define family of algorithms, encapsulates them and
make them interchangeable
Eliminate conditional statements
Cons: communication overhead, increase number of
objects
MVC examples
MVC .net (SEPT\Ebooks and material\TN0910)
MVC Java( SEPT\Ebooks and material\Java MVC exmaple)
Thanks for your listening!