CSC 480 Software Engineering Design With Patterns.

Slides:



Advertisements
Similar presentations
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Advertisements

Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
Design Patterns CMPS Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.
Factory Pattern Building Complex Objects. New is an implementation  Calling “new” is certainly coding to an implementation  In fact, it’s always related.
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
CS 210 Introduction to Design Patterns September 19 th, 2006.
Plab – Tirgul 12 Design Patterns
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Şabloane de Proiectare Daniel POP, Ph.D. 2 The Plan Introducing fundamental patterns (today) 18 design patterns will be covered based on the case study.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Introduction to software design patterns For CSE 3902 By: Matt Boggus.
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
Design Patterns.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Abstract Factory Abstract Factory using Factory Method.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Design Patterns Façade, Singleton, and Factory Methods Team Good Vibrations (1)
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
CS 210 Review Session October 5 th, Head First Design Patterns Chapter 4 Factory Pattern.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
CSC 480 Software Engineering Design With Patterns.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
CS 415 N-Tier Application Development By Umair Ashraf June 22,2013 National University of Computer and Emerging Sciences Lecture # 3 Design Patterns (Observer,Factory,Singleton)
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns Introduction
The Factory Pattern Sanjay Yadav (ISE ).
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Software Design Patterns in Test Automation
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
SE 461 Software Patterns. ABSTRACT FACTORY PATTERN.
SE 461 Software Patterns. FACTORY METHOD PATTERN.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Software Design Patterns
Software Design and Architecture
Software Design and Architecture
Software Engineering Lecture 7 - Design Patterns
Object Oriented Design Patterns - Structural Patterns
CSC 480 Software Engineering
Introduction to Design Patterns
CSC 480 Software Engineering
Design by Abstraction (Continuation) CS 3331 Spring 2005
CSC 480 Software Engineering
Presentation transcript:

CSC 480 Software Engineering Design With Patterns

The Essence of Patterns Each pattern describes a problem which occurs over and over again, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. Christopher Alexander

What Is a Design Pattern? In general, a pattern has four essential elements –The pattern name – abstracts a design problem, its solutions, and consequences (vocabulary) –The problem – explains the context and describes how to represent algorithm as objects –The solution – describes the elements that make up the design, their relationships, responsibilities, and collaborations –The consequences – the results and trade-offs of applying the pattern (evaluation)

The Catalog of GoF Patterns Design patterns are first classified by their purpose –Creational – the process of object creation –Structural – composition of classes and objects –Behavioral – the ways in which classes and objects interact and distribute responsibilities The second criterion is scope –Class – static, fixed at compile-time –Object – more dynamic, changeable at run-time

Design Pattern Space

TEMPLATE METHOD Pattern The Template Method pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

Context An algorithm is applicable for multiple types. The algorithm can be broken down into primitive operations. The primitive operations can be different for each type The order of the primitive operations doesn't depend on the type

Solution Define a superclass that has a method for the algorithm and abstract methods for the primitive operations. Implement the algorithm to call the primitive operations in the appropriate order. Do not define the primitive operations in the superclass, or define them to have appropriate default behavior. Each subclass defines the primitive operations but not the algorithm. (Methods that implement these operations are known as hook methods)

Structure templateMethod() hookMethod1() hookMethod2() GenericClass... hookMethod1()... hookMethod2()... hookMethod1() hookMethod2() ConcreteClass

Example A Generic Function Plotter func() paint() plotFunction() drawCoordinates Plotter func() PlotSine func() PlotCosine Applet Example A Generic Function Plotter Example A Generic Function Plotter (follow link to view source code)

How to Memorize? The Hollywood Principle Don’t call us, we’ll call you. When we design with the Template Method pattern, we’re telling subclasses the same thing Other patterns that make use of the Hollywood Principle –Observer –Factory method (to be discussed shortly)

Façade Pattern The façade pattern provides a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

Context A subsystem consists of multiple classes, making it complicated for clients to use Implementor may want to change subsystem classes Want to give a coherent entry point

Solution Define a facade class that exposes all capabilities of the subsystem as methods The facade methods delegate requests to the subsystem classes The subsystem classes do not know about the facade class

Structure

Example public class Car { Engine engine; //other instance variables public Car() {... } public void start(Key key) { Doors doors = new Doors(); boolean authorized = key.turns(); if (authorized) { engine.start(); updateDashboardDisplay(); doors.lock(); } public void updateDashboardDisplay() {... } }

How to Memorize? The Principle of Least Knowledge Talk only to your immediate friends. This principle guides us to reduce the interactions between objects to just a few close “friends” –Prevent from having a large number of classes coupled together, i.e., less unnecessary dependencies –Prevent from design fragile systems that’s costly to maintain: changes in one part cascade to other parts

FACTORY METHOD Pattern The Factory Method pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Context A type (the creator) creates objects of another type (the product). Subclasses of the creator type need to create different kinds of product objects. Clients do not need to know the exact type of product objects.

Solution Define a creator type that expresses the commonality of all creators. Define a product type that expresses the commonality of all products. Define a method, called the factory method, in the creator type. The factory method yields a product object. Each concrete creator class implements the factory method so that it returns an object of a concrete product class.

Structure

Example public abstract class PizzaStore { public Pizza orderPizza(String type) { Pizza pizza; pizza = createPizza(type); pizza.prepare(); pizza.bake(); pizza.cut(); pizza.box(); } abstract Pizza createPizza(String type); }

Example public class NYPizzaStore { Pizza createPizza(String type) { if (type.equals”cheese”) return new NYStyleCheesePizza(); else if (type.equals”veggie”) return new NYStyleVeggiePizza(); else if (type.equals”clam”) return new NYStyleClamPizza(); else if (type.equals”pepperoni”) return new NYStylePepperoniPizza(); else return null; } }

Example public abstract class Pizza { String name; String dough; String sauce; ArrayList toppings = new ArrayList(); void prepare() { System.out.println(“Preparing ” + name); System.out.println(“Tossing dough...”); System.out.println(“Adding sauce...”); System.out.println(“Adding toppings:”); for (int i=0; i<toppings.size(); i++) System.out.println(“ ” + toppings.get(i)); } void bake() { System.out.println(“Bake for 25 minutes at 350”); } //to be continued

Example //to be continued void cut() { System.out.println(“Cutting the pizza into diagonal slices”); } void box() { System.out.println(“Place the pizza in an official PizzaStore box”); } } public class NYStyleCheesePizza extends Pizza { public NYStyleCheesePizza() { name = “NY Style Sauce and Cheese Pizza”; dough = “Thin Crust Dough”; sauce = “Marinara Sauce”; toppings.add(“Grated Reggiano Cheese”); } }