Factory, Singleton & Strategy All References and Material From: Applying UML and Patterns, 3 rd ed, chpt 26 & 13 BTS530: Major Project Planning and Design.

Slides:



Advertisements
Similar presentations
Visibility Larman, Chapter 19 (with ideas from George Blank of NJIT) CSE432 Object Oriented Software Engineering.
Advertisements

Nov R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple.
Chapter 16. Fig Fig Note: If Sale references nothing then the only thing it is associated with is what references it Note: association name.
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.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
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.
1 Scenario: Audio Clip Imagine that your application played an audio clip Based on user action, a different audio clip may begin playing You want only.
Exam Questions Chain of Responsibility & Singleton Patterns Game Design Experience Professor Jim Whitehead February 4, 2009 Creative Commons Attribution.
NJIT Applying GOF Design Patterns Chapter 26 Applying UML and Patterns Craig Larman Presented By : Naga Venkata Neelam.
NJIT Designing for Visibility Chapter 19 Applying UML and Patterns Craig Larman.
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.
Systems Analysis and Design in a Changing World, Fifth Edition
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
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
12 Systems Analysis and Design in a Changing World, Fifth Edition.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Chapter 7: Object Design Examples with GRASP. Objective Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to.
Abstract Factory Design Pattern making abstract things.
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.
1 ITEC 3010 “Systems Analysis and Design, I” LECTURE 10: Use Case Realizations [Prof. Peter Khaiter]
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.
What to remember from Chap 13 (Logical architecture)
Object Oriented Design Jerry KotubaSYST Object Oriented Methodologies1.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
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
OO Methodology Elaboration Iteration 2 - Design Patterns -
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Chapter 17 Designing with Responsibilities. Fig
OO Methodology Elaboration Phase Iteration 1- Part 3.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Unit IV: GoF Design Patterns
Object Design Examples with GRASP
Unit II-Chapter No. : 5- design Patterns
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Conception OBJET GRASP Patterns
Introduction to Design Patterns
Design Patterns (GoF) contains the creational patterns:
object oriented Principles of software design
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
GoF Design Patterns (Ch. 26)
System Sequence Diagrams
What is Singleton Category: Creational pattern
Singleton Pattern Pattern Name: Singleton Pattern Context
Singleton design pattern
OBJECT ORIENTED ANALYSIS AND DESIGN
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.
Introduction To Design Patterns
Next Gen POS Example GRASP again.
GoF Patterns Ch. 26.
Presentation transcript:

Factory, Singleton & Strategy All References and Material From: Applying UML and Patterns, 3 rd ed, chpt 26 & 13 BTS530: Major Project Planning and Design

Agenda Factory Singleton Strategy

Problem Who creates the adapters (and other similar classes)? If domain object does then we have cohesion (and coupling) issues—the responsibilities are going beyond pure application logic. E.g. If Register creates an instance of SAPAccountingAdapter then its cohesion is lowered=>not acceptable!

Solution: Factory Pattern A Pure Fabrication “factory” object is defined to create objects. Advantages responsibility of complex creation is separated into cohesive helper objects potentially complex creation logic is hidden allows introduction of memory management strategies such as object recycling (for performance enhancement)

Fig. 26.1

Fig The decision of which class to instantiate is made by reading in the class name. What pattern does this follow? (No source code change is required to FactoryServices class for new adapter classes)

Singleton The ServicesFactory class is an example of the Singleton Pattern, which allows exactly one instance of a class. =>Objects need a global and single point of access. =>Define a static method of the class that returns the Singleton.

Fig. 26.6

Singleton Since visibility to public classes is global (most languages), in any part of code, in any method of any class: SingletonClass.getInstance() in order to obtain visibility and send it a message.

public class Register { public void initialize() …blah blah do some work //accessing the singleton Factory via the getInstance call accountingAdapter = ServicesFactory.getInstance().getAccountingAdapter(); …blah blah do some more work } // other methods } // end of class

DBFacade as Singleton

Credit Authorization Example

Scenario: request credit approval from CIBC visa creditAuthAdapter=CreditAuthFactory.getInstance().getCreditAuthAdapter()

We know the following from the previous diagrams:

Points formula Example This is an example of a STRATEGY pattern – the sorting algorithms are interchangeable via a common interface

//Choose which points formula to use System.setProperty("pointsFormulaName","apps.custPoints.PctFormula"); If we were using the “percentage” points formula then somewhere in our startup code we would have the following:

Scenario: Add more points ptsFormula = FormulaFactory.getInstance().getPointsFormula(); return(ptsFormula.convertToPoints(val));

We know the following from the previous diagrams:

Strategy Problem How do you design for related but varying algorithms/policies AND for the ability to change them?

Strategy A Suggestion/Solution Define each algorithm/policy/strategy in a separate class, with a common interface.