Design Patterns Façade, Singleton, and Factory Methods Team Good Vibrations (1)

Slides:



Advertisements
Similar presentations
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Open-closed principle.
Advertisements

Factory Pattern Building Complex Objects. New is an implementation  Calling “new” is certainly coding to an implementation  In fact, it’s always related.
CS 210 Introduction to Design Patterns September 19 th, 2006.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
Informatics 122 Software Design II Lecture 5 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
March Ron McFadyen1 Singleton pattern Singleton is designed to restrict instantiation of a class to one (or a few) objects. Useful when exactly.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
+ Informatics 122 Software Design II Lecture 8 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
Design Patterns.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
Case Studies on Design Patterns Design Refinements Examples.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
Creational Patterns (1) CS350, SE310, Fall, 2010.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
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.
Abstract Factory Abstract Factory using Factory Method.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
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.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
CS 210 Review Session October 5 th, Head First Design Patterns Chapter 4 Factory Pattern.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Introduction
The Factory Pattern Sanjay Yadav (ISE ).
CSC 480 Software Engineering Design With Patterns.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Pat’s Pizza creation Pizza orderPizza(String type){ Pizza pizza; if (type.equals(“cheese”)) { pizza = new CheesePizza(); } else if type.equals(“greek”))
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
SE 461 Software Patterns. FACTORY METHOD PATTERN.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Factory Method. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we.
Factory Method Pattern. Admin SCPI Patner Day Feb. 21 Lunch count Presentation (4-8 min.) Practice on Feb. 16. Morning availablity on Feb21 Brief overview.
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Object-Orientated Analysis, Design and Programming
Design Patterns Spring 2017.
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Low Budget Productions, LLC
Introduction to Design Patterns
Software Design and Architecture
Programming Design Patterns
Software Engineering Lecture 7 - Design Patterns
Object Oriented Design Patterns - Creational Patterns
Object Oriented Design Patterns - Structural Patterns
CS 350 – Software Design Singleton – Chapter 21
Design pattern Lecture 6.
Object-Oriented PHP (1)
Object Oriented Design & Analysis
CSC 480 Software Engineering
Presentation transcript:

Design Patterns Façade, Singleton, and Factory Methods Team Good Vibrations (1)

Why Use Design Patterns? Used to speed up development process. ◦No “reinvention of the wheel”. Improve code readability for coders and maintainers. Creates a starting point for design.

Façade Pattern: Introduction Façade means “frontage”, or “face” in French. ◦Generally used to describe the front of a building (architectural façade). Façade ◦An object that provides a simplified interface to a larger body of code. Structural Design Pattern ◦Ease the identification of relationship between entities

Façade Pattern: Main Idea The community need an easy way to use a complex system. ◦Create a simplified interface to interact with the system.

Façade Pattern: Motivation Allows for software Library ease of use and testing. Make code more readable and maintainable. ◦Structures code. Promotes usability for software users. ◦Usually known as: subroutines, methods, or functions.

Façade Pattern: Limitations Façade is in-between. ◦Interface between the client and the software resources/library. ◦Façade Pattern will limit the features and flexibility that overall affect the power of the user. Solution. ◦Give the user a power options (command prompt, expert options).

Façade Patterns: Limitations Too many methods. ◦Each method is a Façade Design pattern, this is a lot of patterns! Solution. ◦Limit the number of methods the user must interact with.

Façade Patterns: Limitations Useless information. ◦The information from the system resources may be meaningless to the user. Solution. ◦The interface may have to translate the meaning of the information (must do work).

Façade Patterns: Example From Wikipedia

Façade Pattern: Works Cited "Design Patterns - the Facade and Adapter Pattern." Scribd. Web. 24 Jan "Facade Design Pattern." Design Patterns and Refactoring. Web. 24 Jan "Facade Pattern." Wikipedia, the Free Encyclopedia. Web. 24 Jan

Design Pattern: Singleton Singleton Creational Design Pattern David Archer

Design Pattern: Singleton

Singleton =? Global Variable

Design Pattern: Singleton Is the singleton design pattern a good idea?

Design Pattern: Singleton References:

Definition Creational design pattern that lets you define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Diagram Image Credit:

Example Pizza pizza = new ChicagoStyle(); pizza = new HawaiianStyle(); pizza = new NewYorkStyle();

Example Pizza store Pizza order Pizza(){ Pizza pizza = new Pizza(); pizza.prepare(); pizza.bake(); pizza.cut(); pizza.box(); return pizza; }

orderPizza Method “Fix” Pizza orderPizza(String type){ Pizza pizza = new Pizza(); if(type.equals(“cheese”)){ pizza = new CheesePizza();{ else if(type.equals.(“pepperoni”){ pizza = new PepperoniPizza(); else… rest of the menu…. pizza.prepare(); pizza.bake(); pizza.cut(); pizza.box(); return pizza; }

Factory public class SimplePizzaFactory{ public Pizza createPizza(String type){ Pizza pizza = null; if(type.equals(“cheese”)){ pizza = new CheesePizza();{ else if(type.equals.(“pepperoni”){ pizza = new PepperoniPizza(); else… rest of the menu…. return pizza; }

orderPizza Method Revisited public class PizzaStore{ SimplePizzaFactory factory; public PizzaStore(SimplePizzaFactory factory){ this.factory = factory; } public Pizza orderPizza(String type){ Pizza pizza; pizza = factory.createPizza(type); … }

Factory Advantages Decoupling ◦The factory decouples the calling class from the target class. Encapsulation ◦Factory methods encapsulate the creation of objects.

Factory Disadvantages Usually the constructor is often made private to force clients to use the factory methods, as a result since the pattern relies on using a private constructor, the class cannot be extended. We have tight coupling between Factory class and products.

Factory Disadvantages [Cont..] If we add any new concrete product we need a new case statement in the method of Factory class. This violates open/closed design principle. In object-oriented programming, the open/closed principle statesobject-oriented programming "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification";