Design Patterns: Solving Software Design Challenges
Explore the importance of design patterns in Object-Oriented software design, focusing on MVC pattern, Observer pattern, and Strategy pattern with detailed explanations and examples. Learn how expert designers utilize patterns to create flexible and reusable designs.
Design Patterns: Solving Software Design Challenges
E N D
Presentation Transcript
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And http://java.sun.com/blueprints/patterns Created By Eshcar Hilel
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
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
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
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
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
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
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
MVC Structure Design Patterns
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
MVC – Class Diagram Design Patterns
MVC – Class Diagram Strategy Pattern Observer Pattern Design Patterns
MVC – Class Diagram(including interfaces) Design Patterns
MVC – Class Diagram(including interfaces) controller view model Design Patterns
Observer PatternClass Diagram Design Patterns
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
Composite Pattern • View can be nested • Described by the Composite design pattern seen in the lecture Design Patterns
Strategy Pattern – Class Diagram Design Patterns
Strategy Pattern • Define family of algorithms, encapsulates them and make them interchangeable • Eliminate conditional statements • Cons: communication overhead, increase number of objects Design Patterns
Three Tier Model Design Patterns
MVC in Eliza ElizaUI <<ElizaModelInterface>> implements ElizaModel Design Patterns