Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Design Patterns based on book of Gang of Four (GoF) Erich Gamma, Richard Helm, Ralph Johnson, and John VlissidesGang of Four (GoF) Elements of Reusable.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
CS490T Advanced Tablet Platform Applications Design Patterns.
Using the Divide & Conquer Strategy to Teach Java Framework Design Conrad Cunningham, Yi Liu University of Mississippi Cuihua Zhang Northwest Vista College.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Open-closed principle.
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
Inheritance Inheritance Reserved word protected Reserved word super
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
Design Patterns A General reusable solution to a commonly occurring problem in software design. Creational: Deal with object creation mechanisms – Example:
ITEC200 – Week03 Inheritance and Class Hierarchies.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
More design patterns The ADAPTER Pattern Actions and the COMMAND Pattern Actions and the COMMAND Pattern The FACTORY METHOD Pattern The PROXY Pattern The.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
Inheritance using Java
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Design Patterns.
Factory Method A Creational Design Pattern. Factory Method Key Features  Defines an interface for creating objects without needing to know each object’s.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Beware of bugs in the above code; I have only proved it correct, not tried it.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Mohammed Al-Dhelaan CSci 253 Object Oriented Design Instructor: Brad Taylor 06/02/2009 Factory Method Pattern.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
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.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
CSC 480 Software Engineering Design With Patterns.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Design Patterns Definition:
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
CS 772: Global Knowledge Networks V. “Juggy” Jagannathan CSEE, West Virginia University Feb 18, 2002.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
© 2004 Pearson Addison-Wesley. All rights reserved April 10, 2006 Inheritance (part 2) ComS 207: Programming I (in Java) Iowa State University, SPRING.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Design Patterns: MORE Examples
Unit II-Chapter No. : 5- design Patterns
Factory Method Pattern
Factory Patterns 1.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Software Design and Architecture
Factory Method Pattern
UML Class Diagram: class Rectangle
Object Oriented Analysis and Design
Abstract Classes.
Software Engineering Lecture 7 - Design Patterns
Object Oriented Design Patterns - Creational Patterns
CSC 480 Software Engineering
Advanced Java Programming
Abstract Classes and Interfaces
Chapter 8 Class Inheritance and Interfaces
CSC 480 Software Engineering
Abstract Classes and Interfaces
Software Design Lecture : 28.
Presentation transcript:

Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes

Factory Method Pattern This is a set of slides to accompany chapter 8 of Mark Grand’s book Patterns in Java : a catalog of reusable design patterns illustrated with UML (John Wiley & Sons, 1998) Created: 19 August 2004 Revised: 20 April 2010

Context A reusable application that must work with objects from different subclasses of a base class Wish to keep application independent of the actual subclass being used  Invoke only operations on the base class  Delegate creation of the actual subclass object to a special class – factory 1

A Simple Factory 2 Application NameFactoryNamer FirstFirstLastFirst uses creates

A Simple Factory (cont.) public class Namer { public String getFirst () {return first; } public String getLast () {return last; } protected void setFirst ( String f) {first = f; } protected void setLast (String l) {last = l; } private String first; private String last; } 3

A Simple Factory (cont.) public class FirstFirst extends Namer { public FirstFirst (String s) { int i = s.lastIndexOf (" "); if (i > 0) {setFirst (s.substring(0, i).trim() ); setLast (s.substring(i+1).trim() ); } else {setFirst (" "); setLast(s); } 4

A Simple Factory (cont.) 5 public class LastFirst extends Namer { public LastFirst (String s) { int i = s. indexOf (","); if (i > 0) {setFirst (s.substring(i+1).trim() ); setLast (s.substring(0,i).trim() ); } else {setFirst (" "); setLast(s); }

A Simple Factory (cont.) 6 public class NameFactory { public Namer gerNamer (String s) { int i = s. indexOf (","); if (i > 0) return new LastFirst(s); else return new FirstFirst(s); }

A Simple Factory (cont.) Application … NameFactory nf = new NameFactory (); … Namer n = nf.getNamer(s); … String l = n.getLast(); 7

Solution 8 Product operation1 opertation2 … CreationRequestor newDocument … > FactoryIF createProduct (discriminator):Product ConcreteProduct operation1 opertation2 … Factory createProduct (discriminator):Product 1 * 1 * Creates Uses Requests_creation * 1 creator requestor abstract superclass Concrete class instantiated by objects Application independent class Application independent interface Application-specific class. Implement factory interface. Has method to create ConcreateProduct objects

Consequences Creation-requestor class independent from concrete product class Set of product classes may change   only affects factory class 9

Acknowledgement 10 This work was supported by a grant from Acxiom Corporation titled “The Acxiom Laboratory for Software Architecture and Component Engineering (ALSACE).” This work was supported by a grant from Acxiom Corporation titled “The Acxiom Laboratory for Software Architecture and Component Engineering (ALSACE).”