1 / 24

Design Patterns

Learn about the Model-View-Controller (MVC) pattern and other design patterns including Observer, Composite, and Strategy. Understand how these patterns can make your Object-Oriented designs more flexible, elegant, and reusable.

ehaigh
Download Presentation

Design Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And http://java.sun.com/blueprints/patterns Created By Eshcar Hilel

  2. Agenda • Design Patterns - Why? • Model-View-Controller Pattern • What Is the Problem? • Solution, Structure, Responsibilities • Class Diagram • Observer Pattern • (Composite Pattern) • Strategy Pattern • MVC variants examples Design Patterns

  3. 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

  4. 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 Analogy II – Telenovela!! Analogy I - Novelists and playwrights: “Tragically Flawed Hero” (Macbeth, Hamlet...) “The Romantic Novel” Design Patterns

  5. Two Major Principles of Object-Oriented Design: Dynamic binding, polymorphism... • Program to an interface, not an implementation. • Favor object compositions over class inheritance. White-box reuse vs. Black-box reuse See more of this in… OOD Design Patterns

  6. 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 Design Patterns

  7. 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 should not impact the components that provide the core functionality of the enterprise application Design Patterns

  8. 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 Design Patterns

  9. MVC Structure Design Patterns

  10. MVC – Responsibilities • 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 Design Patterns

  11. MVC – Class Diagram Design Patterns

  12. MVC – Class Diagram Strategy Pattern Observer Pattern Design Patterns

  13. MVC – Class Diagram(including interfaces) Design Patterns

  14. MVC – Class Diagram(including interfaces) controller view model Design Patterns

  15. Observer PatternClass Diagram Design Patterns

  16. 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. push model • Other consequences and open issues Design Patterns

  17. Observer Pattern Sequence Diagram Design Patterns

  18. Composite Pattern • View can be nested • Described by the Composite design pattern seen in the lecture Design Patterns

  19. Strategy Pattern – Class Diagram Design Patterns

  20. Strategy Pattern • Define family of algorithms, encapsulates them and make them interchangeable • Eliminate conditional statements • Cons: communication overhead, increase number of objects Design Patterns

  21. MVC Variants

  22. Three Tier Model Design Patterns

  23. MVC in Eliza ElizaUI <<ElizaModelInterface>> implements ElizaModel Design Patterns

  24. The End

More Related