Download presentation
Presentation is loading. Please wait.
Published byAngela Hudson Modified over 5 years ago
1
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin
2
Agenda – Lecture 12a Review & renew. GRASP: protected variations. GoF:
Adapter Façade Factory Strategy Observer 2/28/2019 SOEN 343, © P.Chalin,
3
GRASP Information Expert. Creator. High Cohesion. Low Coupling.
Controller. Polymorphism. Pure Fabrication. Indirection. Protected Variations. 2/28/2019 SOEN 343, © P.Chalin,
4
GRASP Protected Variations
Problem: How to design objects, subsystems, and systems so that the variations or instability in these elements does not have an undesireable impact on other elements? Solution: Identify points of predicted variation or instability; assign responsibility to create a stable interface around them. 2/28/2019 SOEN 343, © P.Chalin,
5
Core PV Mechanisms Encapsulation. Interfaces. Polymorphism.
Indirection, … (Note: we are speaking of mechanisms, not principles) 2/28/2019 SOEN 343, © P.Chalin,
6
PV: Pick Your Battles Beware not to try to overly “future-proof” your designs. Actually, this is true of any principle … 2/28/2019 SOEN 343, © P.Chalin,
7
Gang Of Four Gamma, Helm, Johnson, Vlissides
Some patterns covered in Larman, Chap. 23,… All patterns in XDE As documentation. As dynamic templates. Erich 2/28/2019 SOEN 343, © P.Chalin,
8
GoF Pattern Summary (& Relationhips)
[Picutre (c) GoF CD] 2/28/2019 SOEN 343, © P.Chalin,
9
GoF Pattern Classification
Behavioral Patterns Creational Patterns Structural Patterns 2/28/2019 SOEN 343, © P.Chalin,
10
GoF Behavioral Patterns
Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor 2/28/2019 SOEN 343, © P.Chalin,
11
GoF Creational Patterns
Abstract Factory Builder Factory Method Prototype Singleton 2/28/2019 SOEN 343, © P.Chalin,
12
GoF Structural Patterns
Adapter Bridge Composite Decorator Facade Flyweight Proxy 2/28/2019 SOEN 343, © P.Chalin,
13
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. 2/28/2019 SOEN 343, © P.Chalin,
14
Adapter Suppose we have a tax calculation class (or external library) but the interface is not well suited for our application. 2/28/2019 SOEN 343, © P.Chalin,
15
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 2/28/2019 SOEN 343, © P.Chalin,
16
Adapter (For More than One Class)
What if more than one class (library) needs to be adapted? 2/28/2019 SOEN 343, © P.Chalin,
17
Adapter 2/28/2019 SOEN 343, © P.Chalin,
18
Facade 2/28/2019 SOEN 343, © P.Chalin,
19
Facade 2/28/2019 SOEN 343, © P.Chalin,
20
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. 2/28/2019 SOEN 343, © P.Chalin,
21
Factory Example SOEN 343, © P.Chalin,
Have we seen code like this anywhere? 2/28/2019 SOEN 343, © P.Chalin,
22
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 2/28/2019 SOEN 343, © P.Chalin,
23
(Abstract) Factory Example (GoF)
2/28/2019 SOEN 343, © P.Chalin,
24
FrontControllerServlet RemoveStudentCommand
Factory (in EAs) FrontControllerServlet FrontCommand # processRequest ( ) + init ( ) - getCommand ( ) : FrontCommand + processRequest ( ) - getCommandClass ( ) RemoveStudentCommand ViewStudInfoCommand + processRequest ( ) + processRequest ( ) 2/28/2019 SOEN 343, © P.Chalin,
25
Singleton (Larman Section 23.4) XDE Patterns Singleton
- uniqueInstance : Singleton - attribute # Singleton( ) + getUniqueInstance ( ) : Singleton + getAttr( ) 2/28/2019 SOEN 343, © P.Chalin,
26
Strategy Context / problem: How to design for varying, but related, algorithms or policies? How to design for the ability to change (even dynamically) these algorithms or policies? Solution: Define each algorithm/policy/strategy in a separate class with a common interface 2/28/2019 SOEN 343, © P.Chalin,
27
Strategy 2/28/2019 SOEN 343, © P.Chalin,
28
How Do We Create a Strategy?
2/28/2019 SOEN 343, © P.Chalin,
29
Composite Larman 23.7 (but explanation intertwined with other pattern)
Context / problem: How to treat an aggregate structure of objects the same way as an atomic (non-aggregate) object? Solution: Define classes for composite and atomic objects that implement the same interface. 2/28/2019 SOEN 343, © P.Chalin,
30
Observer Pattern 2/28/2019 SOEN 343, © P.Chalin,
31
Observer How shall we have the display be updated?
Why not … have the Sale inform the display when it changes value. 2/28/2019 SOEN 343, © P.Chalin,
32
What is Wrong With This? 2/28/2019 SOEN 343, © P.Chalin,
33
Presentation Domain Data Source Layers: Dependencies Dependencies
2/28/2019 SOEN 343, © P.Chalin,
34
Layers: Functionality
Presentation Domain Functionality / services Data Source 2/28/2019 SOEN 343, © P.Chalin,
35
Observer Pattern Context / Problem: Different kinds of subscriber objects are interested in the state changes or events of a publisher object, and want to react in their own way when the publisher generates the event. … 2/28/2019 SOEN 343, © P.Chalin,
36
Observer Pattern Solution: Define a “subscriber” or “listener” interface. Subscribers implement this interface. The publisher can dynamically register subscribers who are interested in an event, and notify them when an event occurs. Clarification: Publisher can dynamically process registration requests from subscribers. 2/28/2019 SOEN 343, © P.Chalin,
37
Observers: Illustration
Change requests go down – e.g. one cell in the spread sheet might be changed. Notifications go up (upward dependencies are not ok) 2/28/2019 SOEN 343, © P.Chalin,
38
Observer Class Diagram
(Shown in class) 2/28/2019 SOEN 343, © P.Chalin,
39
Sale Example 2/28/2019 SOEN 343, © P.Chalin,
40
Observer Pattern (GoF book)
2/28/2019 SOEN 343, © P.Chalin,
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.