Factory Method Joey Richey Kevin Gorski. Definition Allows a class developer define the interface for creating an object while retaining control of which.

Slides:



Advertisements
Similar presentations
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Advertisements

The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Template Pattern Kevin Gorski Brian Marler. Template Definition The intent of Template Method is to implement an algorithm in a method, deferring the.
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
Prototype8-1 Prototype CS490 Design Patterns Alex Lo, Rose-Hulman Institute May 13, 2003.
Patterns – Day 9 Façade Composite Reminders: Faculty candidate talk Friday 4:20 PM O-267. Brian Postow: Games and Complexity Theory Another talk on Monday!
Bridge The decoupling of abstraction and implementation.
Iterator Matt G. Ellis. Intent Metsker: Provide a way to access elements of a collection sequentially. GoF: Provide a way to access the elements of an.
Patterns – Day 6 Adapter continued Reminders: Faculty candidate talk today 4:20 PM O-167. No class next Tuesday. Course newsgroup: rhit.cs.patterns.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Abstract Factory Doug Jeffries Tom Schneider CS490 Design Patterns April 3, 2003.
Visitor Matt G. Ellis. Intent Metsker: Let developers define a new operation for a hierarchy without changing the hierarchy classes. GoF: Represent an.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Abstract Classes b b An abstract class is a placeholder in a class hierarchy that represents a generic concept b b An abstract class cannot be instantiated.
+ Informatics 122 Software Design II Lecture 8 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Design Patterns.
PYTHON PROGRAMMING Week 10 – Wednesday. TERMS – CHAPTER 1 Write down definitions for these terms:  Computation  Computability  Computing  Artificial.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
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.
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Unit 20 Factory Method Summary prepared by Kirk Scott 1.
Chapter 16 Factory Method Summary prepared by Kirk Scott 1.
Abstract Factory Design Pattern making abstract things.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
12/6/20041 The Factory Method Pattern Presenters 王世賀 F 陳祐毓 F 張峻銘 F 吳佩達 F 林俊成 F 鄭榮智 F 許書豪 F
GoF Sections Design Problems and Design Patterns.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
Linked List. Iterators Operation to find a link, deleting, and inserting before or after a specified link, also involve searching through the list to.
Factory Method Chris Colasuonno Also known as “Virtual Constructor”
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
The Factory Method Design Pattern Motivation: Class / Type separation – Abstract class serves as type definition and concrete class provides implementation.
Abstract Factory and Factory Method CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
Unit 21 Factory Method Summary prepared by Kirk Scott 1.
Chapter 7: The Adapter Pattern. Object Oriented Adapters Suppose that you have existing software. You have outsourced some of your work and there is a.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
Chapter 17 Abstract Factory Summary prepared by Kirk Scott 1.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Advanced Object-oriented Design Patterns Creational Design Patterns.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
Design and implementation Chapter 7 – Lecture 1. Design and implementation Software design and implementation is the stage in the software engineering.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Factory Method Pattern
Summary prepared by Kirk Scott
Summary prepared by Kirk Scott
Summary prepared by Kirk Scott
Factory Patterns 1.
Software Design and Architecture
Factory Method Pattern
Chapter 17 Abstract Factory
Summary prepared by Kirk Scott
CSE 432 Presentation GoF: Factory Method PH: “To Kill a Singleton”
CS 350 – Software Design Singleton – Chapter 21
Software Design Lecture : 35.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Software Design Lecture : 28.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Presentation transcript:

Factory Method Joey Richey Kevin Gorski

Definition Allows a class developer define the interface for creating an object while retaining control of which class to instantiate. Metsker -Design Patterns Java Workbook

Main Points Creates a new object Returns a type that is an abstract class or interface Is implemented by several classes

Example (Iterators) Iterator() method isolates its caller from knowing which class to instantiate Creates an object that returns a sequence of the elements in a collection

Challenege 16.3 What class is the Iterator object in this code: List list = Arrays.asList(new String[] {“fountain”, “rocket”, “sparkler” }); Iterator i = list.iterator(); Java.util.AbstractList$Itr

File Operations (GoF) Have an application that shows multiple documents to the user The document and application classes are abstract Application class can't predicite which document class it going to be used

Credit Check Example Oozinoz will start letting customers buy fireworks on credit Your task is to develop the credit authorization system The credit agency can be in two states: online and offline Initial design: two separate classes CreditCheckOnline and CreditCheckOffline

Problem: now the user of the classes needs to know which class to instantiate

Solution: Commit to the interface for creating an object but keep control of which class to instantiate (use the Factory pattern) Challenge 16.4 – – Draw a class diagram that establishes a way to create a credit-checking object while retaining control of which class to instantiate.

Solution 16.4

Challenge 16.5 – – Assume that the CreditCheckFactory class has an isAgencyUp() method that tells whether the credit agency is available, and write the code for createCreditCheck().

Solution 16.5 public static CreditCheck createCreditCheck() { if ( isAgencyUp()) { return new CreditCheckOnline(); } else { return new CreditCheckOffline(); }

Factory Method in Parallel Hierarchies A parallel hierarchy is a pair of class hierarchies in which each class in one hierarchy has a corresponding class in the other hierarchy.

Figure 16.2

getAvailable() method forecasts when a machine will complete its current processing to be available for more work This method may require a lot of support Create a separate MachinePlanner hierarchy You need a separate planner class for most machine types, but mixers and fusers are always available for additional work (use BasicPlanner class)

Figure 16.6

Summary The intent of the Factory Method pattern is to define the interface for creating a new object so that a service provider decides which class to instantiate instead of clients. Common in application code and parallel class hierarchy.