SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin
Agenda – Lecture 12a Review & renew. GRASP: protected variations. GoF: Adapter Façade Factory Strategy Observer 2/28/2019 SOEN 343, © P.Chalin,
GRASP Information Expert. Creator. High Cohesion. Low Coupling. Controller. Polymorphism. Pure Fabrication. Indirection. Protected Variations. 2/28/2019 SOEN 343, © P.Chalin,
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,
Core PV Mechanisms Encapsulation. Interfaces. Polymorphism. Indirection, … (Note: we are speaking of mechanisms, not principles) 2/28/2019 SOEN 343, © P.Chalin,
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,
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,
GoF Pattern Summary (& Relationhips) [Picutre (c) GoF CD] 2/28/2019 SOEN 343, © P.Chalin,
GoF Pattern Classification Behavioral Patterns Creational Patterns Structural Patterns 2/28/2019 SOEN 343, © P.Chalin,
GoF Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor 2/28/2019 SOEN 343, © P.Chalin,
GoF Creational Patterns Abstract Factory Builder Factory Method Prototype Singleton 2/28/2019 SOEN 343, © P.Chalin,
GoF Structural Patterns Adapter Bridge Composite Decorator Facade Flyweight Proxy 2/28/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. 2/28/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. 2/28/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 2/28/2019 SOEN 343, © P.Chalin,
Adapter (For More than One Class) What if more than one class (library) needs to be adapted? 2/28/2019 SOEN 343, © P.Chalin,
Adapter 2/28/2019 SOEN 343, © P.Chalin,
Facade 2/28/2019 SOEN 343, © P.Chalin,
Facade 2/28/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. 2/28/2019 SOEN 343, © P.Chalin,
Factory Example SOEN 343, © P.Chalin, Have we seen code like this anywhere? 2/28/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 2/28/2019 SOEN 343, © P.Chalin,
(Abstract) Factory Example (GoF) 2/28/2019 SOEN 343, © P.Chalin,
FrontControllerServlet RemoveStudentCommand Factory (in EAs) FrontControllerServlet FrontCommand # processRequest ( ) + init ( ) - getCommand ( ) : FrontCommand + processRequest ( ) - getCommandClass ( ) RemoveStudentCommand ViewStudInfoCommand + processRequest ( ) + processRequest ( ) 2/28/2019 SOEN 343, © P.Chalin,
Singleton (Larman Section 23.4) XDE Patterns Singleton - uniqueInstance : Singleton - attribute # Singleton( ) + getUniqueInstance ( ) : Singleton + getAttr( ) 2/28/2019 SOEN 343, © P.Chalin,
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,
Strategy 2/28/2019 SOEN 343, © P.Chalin,
How Do We Create a Strategy? 2/28/2019 SOEN 343, © P.Chalin,
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,
Observer Pattern 2/28/2019 SOEN 343, © P.Chalin,
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,
What is Wrong With This? 2/28/2019 SOEN 343, © P.Chalin,
Presentation Domain Data Source Layers: Dependencies Dependencies 2/28/2019 SOEN 343, © P.Chalin,
Layers: Functionality Presentation Domain Functionality / services Data Source 2/28/2019 SOEN 343, © P.Chalin,
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,
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,
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,
Observer Class Diagram (Shown in class) 2/28/2019 SOEN 343, © P.Chalin,
Sale Example 2/28/2019 SOEN 343, © P.Chalin,
Observer Pattern (GoF book) 2/28/2019 SOEN 343, © P.Chalin,