CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.

Slides:



Advertisements
Similar presentations
Creational Design Patterns. Creational DP: Abstracts the instantiation process Helps make a system independent of how objects are created, composed, represented.
Advertisements

OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
Plab – Tirgul 12 Design Patterns
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
Visitor Matt G. Ellis. Intent Metsker: Let developers define a new operation for a hierarchy without changing the hierarchy classes. GoF: Represent an.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Pattern Abstract Factory
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns.
Prof. Hertz (as told by xkcd.com)‏. Computer Science 313 – Advanced Programming Topics.
Factory Method A Creational Design Pattern. Factory Method Key Features  Defines an interface for creating objects without needing to know each object’s.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Tech Talk Go4 Factory Patterns Presented By: Matt Wilson.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Albert Einstein Two things are infinite: the universe & human stupidity; and I'm not sure about the universe.
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
Software Components Creational Patterns.
Beware of bugs in the above code; I have only proved it correct, not tried it.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
1 Computer Science 340 Software Design & Testing Inheritance.
Computer Science 313 – Advanced Programming Topics.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First 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.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
CSC 313 – Advanced Programming Topics. Strategy Pattern Usage public class RubberDuck extends Duck { FlightBehavior flyBehavior; QuackBehavior quackBehavior;
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Introduction
Religious Studies 313 – Advanced Programming Topics.
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
CS 325: Software Engineering March 19, 2015 Applying Patterns (Part B) Code Smells The Decorator Pattern The Observer Pattern The Template Method Pattern.
CSC 480 Software Engineering Lab 5 – Abstract Factory Pattern Oct 30, 2002.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Fred Brooks Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
The Abstract Factory Pattern (Creational) ©SoftMoore ConsultingSlide 1.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
Bjarne Stroustrup I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my.
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.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Design Patterns: MORE Examples
Strategy: A Behavioral Design Pattern
Sections Inheritance and Abstract Classes
Abstract Factory Pattern
MPCS – Advanced java Programming
Factory Patterns 1.
Design Patterns with C# (and Food!)
Section 11.1 Class Variables and Methods
object oriented Principles of software design
Abstract Factory Pattern
Strategy Design Pattern
Intent (Thanks to Jim Fawcett for the slides)
Software Engineering Lecture 7 - Design Patterns
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Advanced Java Programming
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Structural Patterns: Adapter and Bridge
Presentation transcript:

CSC 313 – Advanced Programming Topics

What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete knowledge

Factory Method Intent  Use incomplete types as the declared type of  Local variables, fields, parameters …  Everywhere, since change might occur anywhere  Since it must be concrete, avoid new command  Replace with factory pattern  Design is then much easier to add new classes  Limits changes required when modify existing classes

Factory Method Use/Avoid  Use a factory method pattern when you  Create object, but can choose class instantiated  Hide subclasses of abstract type from client  Must do complex allocation of object stack  Multiple related allocations is also important  Factory patterns so far define 1 factory method  Create 1 type of object (though many subtypes)  Forced linking or chaining allocations impossible

Decorator:Factory::Strategy:?  Factory Method great for decorator pattern  Inheritance-based design of classes in this pattern  Core concept will be wrapped by many decorators  Returns single instance of abstract supertype  But pattern not helpful for Strategy Pattern  Works for single strategy, since need only 1 type  Often allocate & use many strategies, however  Factory needed for each type of strategy, however

Decorator:Factory::Strategy:?

Often Have Related Strategy  Skinnable apps can change look-and-feel  Similar allocations needed for all widgets

Often Have Related Strategy  Skinnable apps can change look-and-feel  Similar allocations needed for all widgets

Often Have Related Strategy  Skinnable apps can change look-and-feel  Similar allocations needed for all widgets

Sets of Choices  Instantiate sets of components to look good  Different set defined by each look-and-feel  Instantiate only from set defined by components  To change skins, must switch set allocating from  More places need this than skinnable apps  Each game level generates class of enemies  Quacking & flying behaviors in SimUDuck  Printing & transmitting behavior of messages in IM  Colors & fonts used in a presentation

Abstract Factory Pattern

Client View of Pattern  Clients use AbstractFactory & ignores details  All of the factory methods declared by this class

Abstract Factory Design  Common code & fields in AbstractFactory  Can be either an abstract class or interface

Abstract Factory UML  Product s are supertypes of useful objects  But pattern will only return subtypes of these

Abstract Factory UML  Client uses subclasses of AbstractFactory  ConcreteFactory s perform actual allocations

Composition over Inheritance  Inheritance makes mixing options easy

Nearly Real Example  Abstract factory generates related types  Building car from parts would be real-life example

Abstract Factory Vitals  Family of related classes from 1 instance  Pattern is also a composition of factory methods  Related or interdependent classes allocated together  Unlike factory method, instantiates multiple types  Skinnable & visual systems clearest example  Scrollbars, tabs, menus, …: many shared concepts  Concrete implementation changes with each look

Abstract Factory Vitals

For Next Lecture  Lab #4 available on Angel  Lab will be due before lab in two weeks (Fri. 3/9)  Read pages in book  How can we make sure only 1 end boss?  What is plural of apocalypse? How to code this?  How are design patterns & Highlander alike?