SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.

Slides:



Advertisements
Similar presentations
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Advertisements

SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Fall 2009ACS-3913 Ron McFadyen1 idea was first put forth by Christopher Alexander (1977) in his work on architectural design principles a pattern is a.
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
Larman, chapters 25 and 26 CSE432 Object-Oriented Software Engineering Glenn D. Blank, Lehigh University Pure Fabrication and “Gang of Four” Design Patterns.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
樣式導向設計 (Pattern-Oriented Design) 課程簡介 Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
CSSE 374: Introduction to Gang of Four Design Patterns
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Pure Fabrication and “Gang of Four” Design Patterns
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
Creational Patterns
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
樣式導向設計 (Pattern-Oriented Design) 課程簡介
Chapter 5:Design Patterns
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Design Patterns with C# (and Food!)
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
GoF Design Patterns (Ch. 26)
Informatics 122 Software Design II
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Design Patterns Part 2: Factory, Builder, & Memento
DESIGN PATTERNS : Introduction
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Informatics 122 Software Design II
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
GoF Patterns Ch. 26.
Presentation transcript:

SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin

Agenda – Lecture 11b DiceGame New GoF patterns. Exercise Set. Summary of redesign done so far. Relationship to patterns and principles. New functionality. New GoF patterns. Exercise Set. 1/12/2019 SOEN 343, © P.Chalin,

What were the patterns we saw … In our DiceGame redesign … 1/12/2019 SOEN 343, © P.Chalin,

Dice Game Refactoring We applied: Indirection principle. Decoupled DiceGame from Dice by inserting an IDice interface in between. Introduced a Simple Factory class, DiceFactory. Made DiceFactory a Singleton. 1/12/2019 SOEN 343, © P.Chalin,

Dice Game: New Functionality Although we added ConstDice we still have a Problem: Our DiceFactory only creates one type of IDice. Solutions: Somehow we want the behavior of createDice() to vary. 1/12/2019 SOEN 343, © P.Chalin,

DiceFactory.createDice(). Possible solutions: DiceFactory can read a System property to determine the class to instantiate (Larman05, p.441). Add a method to factory: Generalize our solution further: Abstract Factory. Any of these solutions will finally allow us to create our test class, … e.g. 1/12/2019 SOEN 343, © P.Chalin,

DiceGameTest JUnit TestCase public void testWinning() { int faceValue = 3; DiceFactory.theOne(). DiceGame game = new DiceGame(); game.roll(); assertEquals("face value", faceValue, game.getFaceValue()); assertTrue("won", game.won()); } 1/12/2019 SOEN 343, © P.Chalin,

New Version of Dice Game Support using a pair of Dice. How can this be added? 1/12/2019 SOEN 343, © P.Chalin,

Multi-Dice Design 1/12/2019 SOEN 343, © P.Chalin,

Composite (Larman05, 26.8) Context/problem How do you treat a group or composite structure of objects the same way (polymorphically) as a non-composite (atomic) object? Solution Define classes for composite and atomic objects so that they implement the same interface. 1/12/2019 SOEN 343, © P.Chalin,

Dice Composite 1/12/2019 SOEN 343, © P.Chalin,

Client Cannot Tell … SOEN 343, © P.Chalin, DiceGame cannot tell whether it is dealing with one or more dice. 1/12/2019 SOEN 343, © P.Chalin,

Composite: Ex. Objects Credits: GoF. 1/12/2019 SOEN 343, © P.Chalin,

Composite: Ex. Class Diagram 1/12/2019 SOEN 343, © P.Chalin,

Must “add” be implemented by Line? In C++ add declared virtual; subclass need not implement it. In Java if add is abstract, then subclasses must implement it. String add(Graphic g) { throw new UnsupportedOperationException(); } Can you think of a better solution? 1/12/2019 SOEN 343, © P.Chalin,

Composite: Clients point-of-view 1/12/2019 SOEN 343, © P.Chalin,

Composite Pricing Strategies Interface Realization 1/12/2019 SOEN 343, © P.Chalin,

Patterns and Principles We have (and still are) studying: Larman’s GRASP GoF Fowler’s EA The most fundamental are the principles. 1/12/2019 SOEN 343, © P.Chalin,

GRASP: Interrelationships This is how Larman illustrates the interrelationships between the GRASP. 1/12/2019 SOEN 343, © P.Chalin,

Patterns apply principles, e.g. … This is how Larman illustrates the interrelationships between the GRASP. 1/12/2019 SOEN 343, © P.Chalin,

Gang-of-four … a closer look 1/12/2019 SOEN 343, © P.Chalin,

Gang Of Four Gamma, Helm, Johnson, Vlissides Some patterns covered in Larman, Chap. 23,… All patterns in XDE As documentation. As dynamic templates. Erich 1/12/2019 SOEN 343, © P.Chalin,

GoF Pattern Summary (& Relationhips) [Picutre (c) GoF CD] 1/12/2019 SOEN 343, © P.Chalin,

GoF Pattern Classification Behavioral Patterns Creational Patterns Structural Patterns 1/12/2019 SOEN 343, © P.Chalin,

GoF Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor 1/12/2019 SOEN 343, © P.Chalin,

GoF Creational Patterns Abstract Factory Builder Factory Method (we saw Simple Factory) Prototype Singleton 1/12/2019 SOEN 343, © P.Chalin,

Factory Context / problem: Who should be responsible for creating objects when there are special considerations, such as complex creation logic, a desire to separate the creation responsibilities for better cohesion, and so forth? Solution: Create a Pure Fabrication object called a Factory. 1/12/2019 SOEN 343, © P.Chalin,

Factory Example SOEN 343, © P.Chalin, Have we seen code like this anywhere? 1/12/2019 SOEN 343, © P.Chalin,

Larman’s comment on prev. figure Note that the factory methods return objects types to an interfacre rather than a class so that the factory can return any implementation of the interface. Factory methods can also 1/12/2019 SOEN 343, © P.Chalin,

(Abstract) Factory Example (GoF) 1/12/2019 SOEN 343, © P.Chalin,

FrontControllerServlet RemoveStudentCommand Factory (in EAs) FrontControllerServlet FrontCommand # processRequest ( ) + init ( ) - getCommand ( ) : FrontCommand + processRequest ( ) - getCommandClass ( ) RemoveStudentCommand ViewStudInfoCommand + processRequest ( ) + processRequest ( ) 1/12/2019 SOEN 343, © P.Chalin,

GoF Structural Patterns Adapter Bridge Composite Decorator Facade Flyweight Proxy 1/12/2019 SOEN 343, © P.Chalin,

Adapter Context / problem How to resolve incompatible interfaces, or provide a stable interface to similar components with different interfaces? Solution: Convert the original interface of a component into another interface, through an intermediate adapter object. 1/12/2019 SOEN 343, © P.Chalin,

Adapter Suppose we have a tax calculation class (or external library) but the interface is not well suited for our application. 1/12/2019 SOEN 343, © P.Chalin,

Adapter Adapter provides an interface suited to the application GoodAsGoldTaxProAdapter getTaxes( Sale ) : List of TaxLineItems computeTax(…):double GoodAsGoldTaxPro Adapter provides an interface suited to the application 1/12/2019 SOEN 343, © P.Chalin,

Adapter (For More than One Class) What if more than one class (library) needs to be adapted? 1/12/2019 SOEN 343, © P.Chalin,

Adapter 1/12/2019 SOEN 343, © P.Chalin,