Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT

Slides:



Advertisements
Similar presentations
Oct R McFadyen1 Recall UML Class Diagram BusRoute BusStopList BusStop BusList BusPersonList Person passengers buses busStops waiting 0..*
Advertisements

Nov R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple.
Chapter 25 GRASP: More Objects with Responsibilities 1CS6359 Fall 2011 John Cole.
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.
NJIT Applying GOF Design Patterns Chapter 26 Applying UML and Patterns Craig Larman Presented By : Naga Venkata Neelam.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
7/16/2015Singleton creational design pattern1 Eivind J. Nordby Karlstad University Dept. of Computer Science.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Client/Server Software Architectures Yonglei Tao.
Larman, chapters 25 and 26 CSE432 Object-Oriented Software Engineering Glenn D. Blank, Lehigh University Pure Fabrication and “Gang of Four” Design Patterns.
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
GRASP Patterns Presented By Dr. Shazzad Hosain. Patterns A pattern describes a problem and solution, and given a name. Examples are Singleton, Adapter,
Chapter 18 Object Design Examples with GRASP. Objectives Design use case realizations –A use-case realization describes how a particular use case is realized.
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)
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
Pure Fabrication and “Gang of Four” Design Patterns
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Introducing Allors Applications, Tools & Platform.
Chapter 36 More Object Design with GoF Patterns 1CS6359 Fall 2011 John Cole.
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 -
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Elaboration Iteration 3 – Part 3 - Persistence Framework -
OO Methodology Elaboration Phase Iteration 1- Part 3.
Design. 2 The Need for Software Blueprints Knowing an object-oriented language and having access to a library is necessary but not sufficient in order.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
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.
Oct 3, Ron McFadyen1 GRASP Patterns 1.Expert 2.Creator 3.Controller 4.Low Coupling 5.High Cohesion.
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
Object Design Examples with GRASP
GRASP – Designing Objects with Responsibilities
Software Design Refinement Using Design Patterns
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Conception OBJET GRASP Patterns
Presentation on GRASP Patterns Submitted by
Design Patterns with C# (and Food!)
Design Patterns (GoF) contains the creational patterns:
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
Design Patterns in Operating Systems
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
Advanced Programming Behnam Hatami Fall 2017.
GoF Design Patterns (Ch. 26)
Singleton Pattern Pattern Name: Singleton Pattern Context
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
GoF Patterns Ch. 26.
Presentation transcript:

Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT Presentation on GoF Design Patterns Submitted by WWW.ASSIGNMENTPOINT.COM www.assignmentpoint.com

GoF Patterns GoF stands for Gang-of-Four According to the four authors of “Design Patterns” book Twenty three GoF patterns such as Adapter Factory Singleton Strategy Composite Facade Observer/Publish-Subscribe/Delegation Event Model www.assignmentpoint.com

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. www.assignmentpoint.com

Adapter www.assignmentpoint.com

Adapter Adapter pattern is a specialization of Polymorphism, Indirection and Protected Variations (GRASP Patterns) www.assignmentpoint.com

Factory Context/Problem: Who creates the adapters? How to determine which class of adapter to create, such as TaxMasterAdapter or GoodAsGoldTaxProAdapter? Solution: Create a Pure Fabrication object called a Factory that handles the creation. Design Principle: Design to maintain a separation of concerns. www.assignmentpoint.com

UML Style www.assignmentpoint.com

Advantages of Factory Separate the responsibility of complex creation into cohesive helper objects. Hide potentially complex creation logic Allow introduction of performance-enhancing memory management strategies, such as object caching or recycling. www.assignmentpoint.com

Singleton Context/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. www.assignmentpoint.com

www.assignmentpoint.com

Implementation and Design Issues Lazy initialization public class ServiceFactory { static ServiceFactory instance = null ; // other variable definition public static synchronized ServiceFactory getIntance () { if (instance == null) { instance = new ServiceFactory() ; } return instance ; // other methods Eager initialization public class ServiceFactory { private static ServiceFactory instance = new ServiceFactory (); public static ServiceFactory getIntance () { return instance ; } // other methods www.assignmentpoint.com

Lazy vs. Eager Approach Lazy one is preferable Creation work (and perhaps holding on to “expensive” resources is avoided in the instance is never actually accessed. The getInstance () lazy initialization sometimes contains complex and conditional creation logic. www.assignmentpoint.com

Static Instance vs. Static Method public class ServiceFactory { static ServiceFactory instance = null ; // other variable definition public static synchronized ServiceFactory getIntance () { if (instance == null) { instance = new ServiceFactory() ; } return instance ; // other methods public class ServiceFactory { private static ServiceFactory instance = new ServiceFactory (); public static ServiceFactory getIntance () { return instance ; } // other methods www.assignmentpoint.com

Static Instance vs. Static Method Static instance is preferred for the following reasons: Static methods are not polymorphic (virtual) and don’t permit overriding in sub-classes in most languages. Most OO remote communication mechanisms, e.g. Java RMI, only support remote-enabling of instance methods, not static methods. You create an object X as singleton, but latter on discovered that it is should not be a Singleton i.e. multiple instances needed. Thus, instance-side solution offers flexibility www.assignmentpoint.com

Use of Adapter, Factory and Singleton public class Register { public void initialize () { // do some work …………….. accAdapter = ServiceFactory.getInstance().getAccountingAdapter () ; } // other methods www.assignmentpoint.com

GoF Patterns Adapter Factory Singleton Strategy Composite Facade Observer/Publish-Subscribe/Delegation Event Model www.assignmentpoint.com

Strategy Context/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. www.assignmentpoint.com

Strategy Public Class Sale { LinkedList list = new LinkedList () ; void addSalesLineItem (SalesLineItem sli) { list.add (sli) ; } int getTotal () { total = 0 for each item in list total = total + item.getSubTotal () ; www.assignmentpoint.com

Strategy Public Class Sale { LinkedList list = new LinkedList () ; void addSalesLineItem (SalesLineItem sli) { list.add (sli) ; } int getTotal () { total = 0 for each item in list total = total + item.getSubTotal () ; Strategy Public Class Sale { int total = 0 ; LinkedList list = new LinkedList () ; ISalePricingStrategy isps = (ISalePricingStrategy) new AbsoluteDiscountOverTrresholdPricingStrategy () ; void addSalesLineItem (SalesLineItem sli) { list.add (sli) ; } int getPreDiscountTotal () { return total ; int getTotal () { total = 0 for each item in list total = total + item.getSubTotal () ; return isps.getTotal (this) ; www.assignmentpoint.com

Strategy Public Class Sale { LinkedList list = new LinkedList () ; void addSalesLineItem (SalesLineItem sli) { list.add (sli) ; } int getTotal () { total = 0 for each item in list total = total + item.getSubTotal () ; Strategy Public Class Sale { int total = 0 ; LinkedList list = new LinkedList () ; ISalePricingStrategy isps = (ISalePricingStrategy) new AbsoluteDiscountOverTrresholdPricingStrategy () ; void addSalesLineItem (SalesLineItem sli) { list.add (sli) ; } int getPreDiscountTotal () { return total ; int getTotal () { total = 0 for each item in list total = total + item.getSubTotal () ; return isps.getTotal (this) ; www.assignmentpoint.com

Creating a Strategy with a Factory www.assignmentpoint.com

Composite Example: Suppose a store has the following policies in efeect today: 20% senior disocunt policy Preferred customer discount of 15% off sales over $400 Today there is $50 off purchases over $500 Buy 1 case of Darjeeling tea, get 15% discount off of everything Suppose a senior who is also a preferred customer buys 1 case of Darjeeling ea and $600 of veggieburgers. What pricing policy should be applied? Policy may be different Best for the customer (lowest price) Best for the store (highest price), probably during recession www.assignmentpoint.com

Composite Context/Problem: How to treat a group or composition structure of objects the same way (poly-morphically) as a non- composite (atomic) object? Solution: Define classes for composite and atomic objects so that they implement the same interface. www.assignmentpoint.com

www.assignmentpoint.com

Collaboration with a Composite www.assignmentpoint.com

GoF Patterns Adapter Factory Singleton Strategy Composite Facade Observer/Publish-Subscribe/Delegation Event Model www.assignmentpoint.com

Strategy Context/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. www.assignmentpoint.com

Façade Context/Problem: A common, unified interface to a disparate set of implementations or interfaces – such as within a subsystem – is required. There may be undesirable coupling to many things in the subsystem, or the implementation of the sub-system may change. What to do? Solution: Define a single point of contact to the subsystem – a façade object that wraps the subsystem. Example: “Rule engine” subsystem, whose specific implementation is not yet known. While creating a line item may be several rules may need to be checked. www.assignmentpoint.com

Façade Public Class Sale { public void makeLineItem (ProductSpecification spec, int quantity) { SalesLineItem sli = new SalesLineItem (spec, quantity) ; if (POSRuleEngineFacade.getInstance ().isInvalid ( sli, this ) ) return ; lineItem.add ( sli) ; } // ….. } // end of class www.assignmentpoint.com

Façade Rule engine subsystem may contain one to hundreds of classes. www.assignmentpoint.com

Observer/ Publish – Subscribe/Delegation Even Model A probable solution When Sale changes its total, it sends a message to a window, asking to refresh its display But then Sale object, a domain model object, knows an UI object Low coupling is not maintained www.assignmentpoint.com

Another Example For Alarm Clock the following things needs to do Show a display dialog box Beep or ring a bell Run a reliability watch dog For upcoming train / plane schedule Display the schedule at different display boards Automatically announce the time thorough mikes www.assignmentpoint.com

Observer/ Publish – Subscribe / Delegation Even Model 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 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. www.assignmentpoint.com

Registration Desk Publish Subscribe and consume Registration www.assignmentpoint.com

Who is the observer, listener, subscriber and publisher www.assignmentpoint.com

Registration Desk Publish Subscribe and consume www.assignmentpoint.com

Assignment Design and implement one of more use cases so that you use the following patterns Singleton Factory Strategy Publish - Subscribe www.assignmentpoint.com