GoF Patterns (GoF) popo.

Slides:



Advertisements
Similar presentations
GRASP The other four What are the first five? What is the goal/purpose of using patterns?
Advertisements

© Keith Vander Linden, Dilbert © United Feature Syndicate, Inc.
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.
Object-Oriented Software Engineering Practical Software Development using UML and Java Design Patterns – Part 2 Sources: Chapter 6: Using Design Patterns,
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.
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.
NJIT Applying GOF Design Patterns Chapter 26 Applying UML and Patterns Craig Larman Presented By : Naga Venkata Neelam.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
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.
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.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
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
BTS430 Systems Analysis and Design using UML Design Patterns.
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
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!
GRASP: Designing Objects with Responsibilities
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
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?
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain.
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
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
GRASP – Designing Objects with Responsibilities
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
By SmartBoard team Adapter pattern.
Conception OBJET GRASP Patterns
Introduction to Design Patterns
Design Patterns (GoF) contains the creational patterns:
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
object oriented Principles of software design
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
Presented by Igor Ivković
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
GoF Design Patterns (Ch. 26)
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.
Chapter 25 GRASP The other four.
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Chapter 25 GRASP The other four.
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.
GoF Patterns Ch. 26.
Presentation transcript:

GoF Patterns (GoF) popo

Gang of Four (GoF) is a set of 23 object design patterns GoF Patterns (GoF) Gang of Four (GoF) is a set of 23 object design patterns Authored by four people, Gamma, Helm, Johnson and Vlissides, are therefore called the Gang of Four (GoF) design patterns. Some of the important GoF patterns are. popo

GoF Patterns (GoF) Adapter (GoF) Factory (GoF) Singleton (GoF) Strategy (GoF) Facade (GoF) popo

GoF Patterns (GoF) Adapter (GoF) Pattern Name: Adapter 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. popo

Each has a different API, which can't be changed. GoF Patterns (GoF) Adapter (GoF) Example The NextGen POS system needs to support several kinds of external third-party services, including tax calculators, credit authorization services, inventory systems, and accounting systems, among others. Each has a different API, which can't be changed. popo

GoF Patterns (GoF) Adapter (GoF) A solution is to add a level of indirection with objects that adapt the varying external interfaces to a consistent interface used within the application popo

The adapter pattern can be related to some GRASP patterns. GoF Patterns (GoF) Adapter (GoF) The adapter pattern can be related to some GRASP patterns. Adapter supports Protected Variations with respect to changing external interfaces or third-party packages through the use of an Indirection object that applies interfaces and Polymorphism. popo

GoF Patterns (GoF) Factory (GoF) This is also called Simple Factory or Concrete Factory. The adapter raises a new problem in the design: In the Adapter pattern solution for external services with varying interfaces, who creates the adapters? And how to determine which class of adapter to create, such as TaxMaster-Adapter or GoodAsGoldTaxProAdapter popo

GoF Patterns (GoF) Factory (GoF) If any domain object creates them, The responsibilities of the domain object are going beyond pure application logic. This will leads to: Design to maintain extra. Here, the domain layer of software objects emphasizes relatively pure application logic responsibilities, Whereas a different group of objects is responsible for the concern of connectivity to external systems. popo

GoF Patterns (GoF) Factory (GoF) A common alternative in this case is to apply the Factory pattern, In which a Pure Fabrication "factory" object is defined to create objects. Factory objects have several advantages: Separate the responsibility of complex creation into helper objects. Hide potentially complex creation logic. Allow introduction of performance-enhancing memory management strategies, such as object caching or recycling popo

GoF Patterns (GoF) Factory (GoF) Pattern Name: 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, and so on? Solution: Create a Pure Fabrication object called a Factory that handles the creation. popo

Then, How to get visibility to this single Services instance? GoF Patterns (GoF) Singleton (GoF) The Factory pattern raises another new problem in the design: Who creates, and how is it accessed? The process and the methods that may need to be called from various places in the code, as different places need access to the adapters for calling on the external services. Then, How to get visibility to this single Services instance? popo

This is possible but inconvenient; GoF Patterns (GoF) Singleton (GoF) One solution is pass the instance as a parameter to wherever a visibility need This is possible but inconvenient; An alternative is the Singleton pattern. It support global visibility or a single access point to a single instance of the class rather than some other form of visibility popo

Pattern Name: Singleton Problem: GoF Patterns (GoF) Singleton (GoF) Pattern Name: Singleton Problem: Exactly one instance of a class is allowed. It is a "singleton" Objects need a global and single point of access. Solution: Define a static method of the class that returns the singleton. popo

GoF Patterns (GoF) Singleton (GoF) The key idea is that class X defines a static method that itself provides a single instance of X. With this approach, a developer has global visibility to this single instance popo

GoF Patterns (GoF) Singleton (GoF) Example public class ServicesFactory { // eager initialization static ServicesFactory instance = new ServicesFactory( ) ; public static ServicesFactory getlnstance() { return instance; } // other methods... popo

GoF Patterns (GoF) Singleton (GoF) popo

GoF Patterns (GoF) Strategy (GoF) The next design problem to resolved more complex pricing logic, such as a discount for the day, senior citizen discounts, and so on. The pricing strategy for a sale can vary. During some time it may be 10% off all sales, later it may be Rs10/- off if the sale total is greater than Rs200/-, and may be other variations. How do we design for these varying pricing algorithms? popo

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

GoF Patterns (GoF) Strategy (GoF) Since the behavior of pricing varies by the strategy , we create multiple SalePricingStrategy classes, each with a polymorphic getTotal method Each getTotal method takes the Sale object as a parameter, so that the pricing strategy object can find the pre-discount price from the Sale, and then apply the discounting rule. The implementation of each getTotal method will be different. popo

GoF Patterns (GoF) Strategy (GoF) popo

GoF Patterns (GoF) popo Facade (GoF) A facade is an object that provides a simplified interface to a larger body of code, such as a class library A facade can: make a software library easier to use, understand and test, since the facade has methods for common tasks. make the library more readable, reduce dependencies of outside code on the inner workings of a library, since most code are more flexibility in developing the system; wrap a poorly designed collection of APIs with a single well-designed API popo

GoF Patterns (GoF) Facade (GoF) popo

GoF Patterns (GoF) popo Facade (GoF) Pattern Name: Facade Problem: A common, interfaces 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 facade object that wraps the subsystem. This facade object presents a single unified interface and is responsible for collaborating with the subsystem components. popo