March 200592.3913 R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (in Larman) Prototype Singleton.

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.
Design Patterns CS is not simply about programming
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
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.
Fall 2009ACS-3913 R McFadyen1 GoF Patterns, chapter 26 GoF book presents 23 patterns: Creational – 5 Structural – 7 Behavioural – 11 Larman discusses 7.
March R McFadyen1 Façade. March R McFadyen2 Facade P Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun.
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.
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.
Larman, chapters 25 and 26 CSE432 Object-Oriented Software Engineering Glenn D. Blank, Lehigh University Pure Fabrication and “Gang of Four” Design Patterns.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
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
SOEN 343 Software Design Section H Fall 2006 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
Pure Fabrication and “Gang of Four” Design Patterns
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)
OO Methodology Elaboration Iteration 2 - Design Patterns -
Creational Patterns
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 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
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Object-Oriented Analysis and Design Week 12, 2009.
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.
Design Patterns (GoF) contains the creational patterns:
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
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)
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.
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:

March R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (in Larman) Prototype Singleton (in Larman) 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 GoF Patterns

March R McFadyen2 Simple Factory ( nd edition or rd edition) 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. Simple Factory Pattern

March R McFadyen3 Textbook example The NextGen POS system supports several kinds of 3 rd 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. Simple Factory Pattern

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

March R McFadyen5 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. Simple Factory Pattern ServicesFactory accountingAdapter:… inventoryAdapter:… taxCalculatorAdapter:… getAccountingAdapter():… getInventoryAdapter():… getTaxCalculatorAdapter():…

March R McFadyen6 Singleton ( nd edition or rd edition) 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? Singleton Pattern

March R McFadyen7 Singleton In Java, you would have code such as: Public static synchronized ServicesFactory getInstance() { If (instance == null) Instance := new ServicesFactory() Return instance } Singleton Pattern 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.

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

March R McFadyen9 Singleton Pattern Suppose an instance of the ServicesFactory is created and, later on, a message, getTaxCalculatorAdapter(), is passed to this instance. :Register :ServicesFactory getInstance() ServicesFactory create() getTaxCalculatorAdapter()

March R McFadyen10 Singleton Pattern Figure nd edition :Register :AccountingAdapter getAccountingAdapter() > :ServicesFactory create() post() By applying the singleton stereotype to this object, they imply the getInstance method was used to instantiate it.

March R McFadyen11 Singleton Pattern See Figure rd edition :Register :SAPAccountingAdapter getAccountingAdapter() create() post() By applying the singleton stereotype to this object, they imply that getInstance method was used to instantiate it. 1 :ServicesFactory

March R McFadyen12 Singleton Pattern The text makes reference to Lazy Instantiation – The ServicesFactory object was created when it was needed, and not before :Register :AccountingAdapter getAccountingAdapter() > :ServicesFactory create() post()