Contents

 Design Patterns - Why?

 Model-View-Controller Pattern

MVC
Nguyen Trung Lap Hoa Sen University

 Observer Pattern  (Composite Pattern)  Strategy Pattern  MVC variants examples

Design Patterns - Why?
 Designing OO software is hard  Designing reusable OO software – harder  Experienced OO designers make good design  New designers tend to fall back on non-OO techniques used before  Experienced designers know something – what is it?

Design Patterns - Why?
 Expert designers know not to solve every problem from first principles  They reuse solutions  These patterns make OO designs more flexible, elegant, and ultimately reusable

Model-View-Controller Pattern
 MVC consists of three kinds of objects:
– Model – the application object – View – UI (screen presentation) – Controller – defines the way the UI reacts to user inputs

MVC – What Is the Problem?
 The same enterprise data needs to be accessed when
presented in different views: e.g. HTML, JFC/swing, XML  The same enterprise data needs to be updated through different interactions  Supporting multiple types of views and interactions

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 Strategy Pattern MVC – Class Diagram (including interfaces) Observer Pattern .MVC – Solution  Separate core business model functionality from the MVC Structure 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. and maintain MVC – Responsibilities  Model – the model represents enterprise data and the business rules that govern access to and updates of this data MVC – Class Diagram  View – the view renders the contents of a model. test.

push model Observer Pattern Sequence Diagram ??? notify( ) update( ) getState( ) for each observer : ConcreteSubject ob1 : ConcreterObserver ob2 : ConcreterObserver update( ) getState( )  Other consequences and open issues Composite Pattern  View can be nested  Described by the Composite design pattern seen in the lecture Strategy Pattern – Class Diagram .MVC – Class Diagram controller (including interfaces) Observer Pattern Class Diagram view model Observer Pattern  Define a one-to-many dependency. all the dependents are notified and updated automatically  The interaction is known as publish-subscribe or subscribe-notify  Avoiding observer-specific update protocol: pull model vs.

Strategy Pattern  Define family of algorithms.net (SEPT\Ebooks and material\TN0910)  MVC Java( SEPT\Ebooks and material\Java MVC exmaple) Thanks for your listening! . increase number of objects MVC examples  MVC . encapsulates them and Three Tier Model make them interchangeable  Eliminate conditional statements  Cons: communication overhead.

Sign up to vote on this title
UsefulNot useful