Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
Plab – Tirgul 12 Design Patterns
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Design Patterns Ref : Chapter 15 Bennett et al. useful groups of collaborating classes that provide a solution to commonly occuring problems. provide.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns Trends and Case Study John Hurst June 2005.
Design Patterns.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Aniruddha Chakrabarti
GUI Tradeoffs COM379 University of Sunderland Harry R. Erwin, PhD.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
GoF Sections Design Problems and Design Patterns.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Patterns COM379 University of Sunderland James Malone.
Design Patterns Introduction General and reusable solutions to common problems in software design SoftUni Team Software University
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
CSC 480 Software Engineering Design With Patterns.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
Design Patterns Introduction
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Advanced Object-oriented Design Patterns Creational Design Patterns.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
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.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Abstract Factory Pattern
Design Patterns: Brief Examples
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
Introduction to Design Patterns
Low Budget Productions, LLC
Introduction to Design Patterns
object oriented Principles of software design
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Object Oriented Design Patterns - Creational Patterns
DESIGNING YOUR SYSTEM.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
DESIGN PATTERNS : Introduction
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Creational Patterns.
Informatics 122 Software Design II
CSC 480 Software Engineering
Presented by Igor Ivković
Presentation transcript:

Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD

Pattern Languages Alexander (1977) invented the idea of a pattern language as a practical tool for describing architectural expertise in some domain. The elements of a pattern language are patterns. Each pattern describes a problem that occurs over and over again, and then describes the core of the solution to that problem in such a way that it can be reused many times, never once doing it the same way. A pattern isn’t considered proven until it has been used at least three times in real applications.

Design Patterns The four essential elements (Gamma, et al) of a design pattern are: –A descriptive name –A problem description that shows when to apply the pattern and to what contexts. The description explains how it helps to complete larger patterns. –A solution that abstractly describes the constituent elements, their relationships, responsibilities, and collaborations. –The results and trade-offs that should be taken into account when applying the pattern.

Resources Gamma, Helm, Johnson, and Vlissides, 1995, Design Patterns, Addison-Wesley. Cooper, 1998, The Design Patterns Java Companion, Addison-Wesley, available free from the sample code in the book is available as The Portland Pattern Repository: Alexander, 1977, A Pattern Language: Towns/Buildings/ Construction, Oxford University Press. (For historical interest.)

Some Creational Patterns Builder Factory Method Abstract Factory Prototype Singleton

Builder Ever need to build a complex object in a specified way from different concrete classes? E.g., an airplane has wings, tail, fuselage, engines, landing gear, etc., all selected from families of components. The Builder class is an abstract interface for a construction process that puts together a system of a specific type. Positives: –Encapsulation –Code isolation –Fine control over the build process Negatives: –Only certain types of composite objects lend themselves to a build process. And don’t build a whale using the build process for a bird.

Factory Method You need an object, but which subtype of the object needs to be decided later. This can be a particularly problem during initialization, as it means the file/object loader has to know every possible subclass. The solution to this is called the ‘factory method’ or ‘object factory’. Positives: –Flexibility –Can connect parallel class hierarchies Negatives: –Forces subclassing of the base class

Abstract Factory Ever need to provide a family of related or dependent objects, where the underlying concrete classes need to be specified based on implementation details not of concern to the using program? The pattern that does this is called an ‘abstract factory’. We will discuss Modified Visual Proxy in Lecture 19. Positives: –Enforces encapsulation –Makes exchanging families easy –Produces consistency Negatives: –Adding new families is difficult. Each family needs a concrete factory implementing the AbstractFactory. If many factors must be considered, there can be an explosion in the amount of code.

Prototype Uses clone() rather than new to create objects. You can specialize a prototype object at program start-up to address implementation issues that cannot be specified at compile time. Positives: –Allows you to bind design details at run-time. –Allows you to define a pseudo-subclass at run-time parameterized or indexed by a numeric value. –Allows you to duplicate object data if a large set of objects need to be defined with common characteristics. –Avoids excessive subclassing. –Allows you to do dynamic loading of classes. Negatives: –Everything needs to implement clone(). –Designing this approach into a class is highly non-trivial.

Singleton Ensures a class has a globally accessible unique instance. Sometimes you need a class with only one instance, and sometimes you need global access to a class. Positives: –Avoids the need to link objects at system initialization. –Sometimes you need it badly. –Supports persistence. The local copy can be a proxy for a copy kept on disk. –Reduced name space pollution. –Can be modified to support multiple instances using a Map. Negatives: –Has to be carefully implemented. –Sometimes it’s just not useful.

Examples from Book