GoF Patterns Ch. 26.

Slides:



Advertisements
Similar presentations
C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
Advertisements

Nov R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple.
Fall 2009ACS-3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (Simple Factory) Prototype.
March R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (in Larman) Prototype Singleton.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Fall 2009ACS-3913 R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) More GRASP Patterns.
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
Fall 2009ACS-3913 R McFadyen1 Singleton Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure.
NJIT Applying GOF Design Patterns Chapter 26 Applying UML and Patterns Craig Larman Presented By : Naga Venkata Neelam.
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
Chapter 25 More Design Patterns.
Client/Server Software Architectures Yonglei Tao.
Design Patterns.
Chapter 17. GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities.
CSSE 374: Introduction to Gang of Four Design Patterns
CSSE 374: 3½ Gang of Four Design Patterns These slides derived from Steve Chenoweth, Shawn Bohner, Curt Clifton, and others involved in delivering 374.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Factory, Singleton & Strategy All References and Material From: Applying UML and Patterns, 3 rd ed, chpt 26 & 13 BTS530: Major Project Planning and Design.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Next Gen POS Example GRASP again. Same Patterns Different Example!
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Software Engineering 1 Object-oriented Analysis and Design Chap 24 Iteration 2 More Patterns.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Patterns Roberto Damiani Mendes. Roteiro Definition; Definition; Architecture Patterns; Architecture Patterns; Design Patterns; Design Patterns; GRASP.
Design Patterns Introduction
Introduction to Object-Oriented Programming Lesson 2.
Chapter 17 Designing with Responsibilities. Fig
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
More Patterns CS 124. More Basic Patterns Patterns you’ve already seen (without knowing it) Observer / Listener Wrapper Composite Decorator / Filter Patterns.
GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain.
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.
Object-Oriented Analysis and Design Week 12, 2009.
OO Methodology Elaboration Iteration 3 – Part 3 - More Design Patterns -
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Unit IV: GoF Design Patterns
Chapter 10 Design Patterns.
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Conception OBJET GRASP Patterns
Design Patterns with C# (and Food!)
Design Patterns (GoF) contains the creational patterns:
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
Presented by Igor Ivković
Design Patterns in Operating Systems
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
GoF Design Patterns (Ch. 26)
Object Oriented Design Patterns - Structural Patterns
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
GoF Design Patterns (Ch. 26)
CS 350 – Software Design Singleton – Chapter 21
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Presented by Igor Ivković
Next Gen POS Example GRASP again.
Presentation transcript:

GoF Patterns Ch. 26

Adapter Pattern 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.

Adapter Next gen POS needs to interface with several third-party services: tax calculators, credit authorization services, inventory systems, and accounting. Each has a different API which cannot be changed. Add indirection: adapts to external, has consistent internal I/F - adapter

Using the Adapter Includes pattern in type name Façade – wrap access to system or subsystem with a single object Adapter supports protected variations – changing ext interfaces, indirection, polymorphism

Most design patterns are seen as specialization of GRASP Adapter: indirection and protected variation that uses polymorphism

Updating the domain model! Discover noteworthy domain concepts after creating a new class

Factory 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, etc? Solution: Create a Pure Fabrication object called Factory that handles the creation. Design to maintain separation of concerns, the more distinct the concerns, the more cohesive is the purpose! Factory object is designed to create objects separate responsibility into a cohesive helper object hide complex creation logic allow performance-enhancing memory management through caching or recycling

Factory Dynamically loads the class!!! – in this case from an external property Protected variations if adapter changes, without changing source code of factory we can create new adapters! Factory ~ Singleton

Singleton Problem: Exactly one instance of a class is allowed in a “singleton”. Objects need a global and single point of access. Solution: Define a static method of the class that returns the singleton. Who creates the factory and how is it accessed? Static is a form of visibility: we do not need to pass the object as a parameter to be able to access its methods

Singleton Class X defines a static method getInstance that itself provides an instance of X Lazy (preferred, less work!, check if null, then init) vs Eager initialization

Implicit getInstance SIngleton Wy not make service methods static methods of the class itself? Static methods not polymorphic, do not permit overriding Related: factory, façade

Adapter, Factory, & Singleton Building blocks To handle the problem of varying interfaces for external services, let’s use Adapters generated from a Singleton Factory

Strategy Problem: How to design for varying, but related, algorithms or policies? How to design for the ability to change algorithms or policies? Solution: Define each algorithm/policy/strategy in a separate class with a common interface.

Strategy Multiple sale pricing strategy classes, polymorphic getTotal method

Strategy Application

Creating Strategy with Factory

Creating Strategy with Factory

Creating a strategy

Composite Problem: How to treat a group or composition structure of bjects 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.

Composite Outer composite object contains a list of inner objects and both the outer and inner objects implement the same interface. CompositeBestForCustomerPRicingStrategy inherits the attribute pricing Strategies

Composite

Creating Composite Strategy

Pricing strategy for customer discount

Pricing strategy for customer discount Based on polymorphism and protected variations

Recap - GoF Adapter Factory Singleton Strategy Composite Still left: Façade Observer

Facade Problem: A common, unified interface to disparate set of implementations or interface such as within a subsystem is required. There may be undesirable coupling to many things in the subsystem, or the implementation of the subsystem may change. What to do? Solution: Define a single point of contact to the subsystem, a façade object that wraps the subsystem. This façade object presents a single, unified interface and is responsible for collaborating with the subsystem components.

Façade Front end interface, hides subsystem behind an object Singleton pattern Separation of concerns

Observer

Observer (Publish-Subscribe) 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 unique way when the publisher generates an event. Moreover, the publisher wants to maintain low coupling to the subscribers. What to do? 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.

Observer

Observer

Practice with patterns http://www.vincehuston.org/dp/patterns_quiz.html http://www.dofactory.com/net/design-patterns https://www.proprofs.com/quiz-school/story.php?title=Quiz-GoF- Design-Patterns-1&user_name=I https://www.tutorialspoint.com/design_pattern/design_pattern_online _quiz.htm