Design Patterns (GoF) contains the creational patterns:

Slides:



Advertisements
Similar presentations
Chapter 5: The Singleton Pattern
Advertisements

SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Sequence Diagram Objects are represented horizontally across the top of the diagram Each object has a lifeline some exist before and/or after some are.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
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.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
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.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
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.
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Feb 4, Ron McFadyen1 founded on principles of good OO design idea was first put forth by Christopher Alexander (1977) in their work concerning.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
CSSE 374: Introduction to Gang of Four Design Patterns
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns 1.
Advanced Programming Rabie A. Ramadan 7.
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)
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
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.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Creational Patterns
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
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?
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Singleton Pattern Presented By:- Navaneet Kumar ise
The Singleton Pattern (Creational)
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
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,
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
GoF Patterns (GoF) popo.
MPCS – Advanced java Programming
Design Patterns – Chocolate Factory (from Head First Design Patterns)
Week 2, Day 1: The Factory Method Pattern
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Singleton Pattern Command Pattern
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
Chapter 6: Using Design Patterns
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)
Figure 30.2 Layers in NextGen
Singleton Pattern Pattern Name: Singleton Pattern Context
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.
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.
Design pattern Lecture 6.
GoF Patterns Ch. 26.
Presentation transcript:

Design Patterns (GoF) contains the creational patterns: GoF Patterns Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple Factory) Prototype Singleton (23.4) These are creational patterns for the instantiation process Help to make a system independent of how its objects are created They hide how instances of classes are created November 2004 91.3913 R McFadyen

Simple Factory Pattern Problem: who should be responsible for creating objects when there are special considerations such as complex creational logic, … Solution: create a Pure Fabrication object called a Factory that handles the creation. (The factory creates objects.) E.g. Which adapters should exist when NextGenPOS is running? The text presents a class that determines which adapters will be instantiated. November 2004 91.3913 R McFadyen

Simple Factory Pattern Textbook example The NextGen POS system supports several kinds of 3rd party services. For example: tax calculators such as TaxMaster and Good As Gold, account packages such as SAP and Great Northern. The support is provided through “adapters”. The text is concerned with determining the class that should create the required adapters. Choosing a class in the domain model will lower the cohesion of that class. Instead we apply pure fabrication, and using the Simple Factory Pattern, we have a Factory class that has the responsibility to create such adapter objects. November 2004 91.3913 R McFadyen

Simple Factory Pattern Textbook example ServicesFactory is a class that is responsible for creating the various adapters required in NextGenPOS. It is a factory. ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():… November 2004 91.3913 R McFadyen

Simple Factory Pattern Textbook example Suppose an external source contains the names of the adapters that are to be used. This source is available at runtime. ServicesFactory accesses this source and instantiates the correct adapter objects. Different adapters will be instantiated for different NextGenPOS systems. ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():… November 2004 91.3913 R McFadyen

Solution: use a static method of the class to return the singleton Singleton Pattern Singleton (23.4) Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure a class has only one instance. Solution: use a static method of the class to return the singleton Factories and Facades are usually singletons. Textbook problem: how do we control the instantiation of the ServicesFactory? November 2004 91.3913 R McFadyen

Singleton Pattern Singleton (23.4) In Java, you would have code such as: Public static synchronized ServicesFactory getInstance() { If (instance == null) Instance := new ServicesFactory() Return instance } The point of the above is that only one instance is ever created. If one already exists, then the create is bypassed and the reference to the existing object is returned. November 2004 91.3913 R McFadyen

Singleton Pattern Singleton (23.4) In Java, you would have code such as: Public static synchronized ServicesFactory getInstance() { If (instance == null) Instance := new ServicesFactory() Return instance } The “synchronized” keyword ensures that only one “thread” runs this code at a time. The text refers to a “critical section”. November 2004 91.3913 R McFadyen

Singleton Pattern Suppose an instance of the ServicesFactory is created and, later on, other messages are passed to this instance. (Note: on page 350 the text makes reference to the situation illustrated below as “uninteresting”) :Register ServicesFactory getInstance() create() :ServicesFactory getTaxCalculatorAdapter() getAccountingAdapter() November 2004 91.3913 R McFadyen

<<Singleton>> Singleton Pattern Figure 23.6 By applying the <<singleton>> stereotype to this object, they are implying that the getInstance method was used to instantiate it. <<Singleton>> :ServicesFactory :Register getAccountingAdapter() create() :AccountingAdapter post() November 2004 91.3913 R McFadyen

<<Singleton>> Singleton Pattern The text makes reference to lazy instantiation – The ServicesFactory object was created when it was needed, and not before. Creating it before would be eager instantiation <<Singleton>> :ServicesFactory :Register getAccountingAdapter() create() :AccountingAdapter post() November 2004 91.3913 R McFadyen