Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin."— Presentation transcript:

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

2 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,

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

4 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,

5 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,

6 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,

7 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,

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

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

10 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,

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

12 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,

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

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

15 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,

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

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

18 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,

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

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

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

22 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,

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

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

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

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

27 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,

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

29 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,

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

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

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

33 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,

34 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,

35 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,

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

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


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

Similar presentations


Ads by Google