BUILDER, MEDIATOR, AND DECORATOR Team 2 (Eli.SE).

Slides:



Advertisements
Similar presentations
Design Patterns. General reusable solution to a commonly occurring problem in software design software design – Not a finished design that can be transformed.
Advertisements

Chapter 3: The Decorator Pattern
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
SE-2811 Dr. Mark L. Hornick 1. The Decorator Pattern SE-2811 Dr. Mark L. Hornick 2.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
The Decorator Design Pattern (also known as the Wrapper) By Gordon Friedman Software Design and Documentation September 22, 2003.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns.
Department of Computer Science, York University Object Oriented Software Construction 16/09/ :52 PM 0 COSC3311 – Software Design Decorator Pattern.
Structural Pattern: Decorator There are times when the use of subclasses to modify the behavior of individual objects is problematic. C h a p t e r 4.
Emeka Egbuonye CSPP March 02,2010 The Mediator Pattern.
Team 5: The Infinite Loops Gloria Berumen Patricia Martinez Jose Roberto Salcido Michelle Soto Jose Luis Yanez Omar Zorrilla Design Pattern.
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.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Design patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Design Patterns Façade, Singleton, and Factory Methods Team Good Vibrations (1)
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
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.
GoF: Document Editor Example Rebecca Miller-Webster.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
By James Sheets. An object creational pattern. Separates the construction of a complex object from its representation so that the same construction process.
Structural Design Patterns
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Object Oriented Software Development
Mediator Kensho Tsuchihashi. Mediator Page 2 Table of Contents 1.What is Mediator? 2.What problem does Mediator solve? 3.Advantage and Disadvantage 4.Additional.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
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.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Design patterns.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns Introduction
Creational Pattern: Builder When a complex object needs to be created, it is sometimes beneficial to separate the construction of the object from its.
The Factory Pattern Sanjay Yadav (ISE ).
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
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.
S.Ducasse Stéphane Ducasse 1 Decorator.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
Singleton Pattern Presented By:- Navaneet Kumar ise
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
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.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
SE 461 Software Patterns. FACTORY METHOD PATTERN.
Design Patterns: MORE Examples
Object-Orientated Analysis, Design and Programming
Design Patterns Spring 2017.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Intent To provide a framework to manage the process of software salvage and promote loose coupling through message passing. Salvage means recycling significant.
Decorator Design Pattern
Object Oriented Analysis and Design
Multiuser Protection and the Mediator Pattern
Programming Design Patterns
Decorator Pattern Intent
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Structural Patterns: Adapter and Bridge
7. Decorator SE2811 Software Component Design
Informatics 122 Software Design II
Decorator Pattern.
Presentation transcript:

BUILDER, MEDIATOR, AND DECORATOR Team 2 (Eli.SE)

BUILDER

Builder Pattern  Multiple objects can be constructed with the same interface  Similar to Factory Pattern  Focuses on building items step-by-step

Class Diagram

Pizza  Multiple different types, same process  Build dough  Build sauce  Build toppings

PizzaBuilder abstract class PizzaBuilder { protected Pizza pizza // has 3 attributes: dough, sauce, toppings public Pizza getPizza() { return pizza; } public void createNewPizzaProduct() { pizza = new Pizza(); } abstract public void buildDough(); abstract public void buildSauce(); abstract public void buildToppings(); }

HawaiianPizzaBuilder class HawaiianPizzaBuilder extends PizzaBuilder { public void buildDough() { pizza.setDough("cross"); } public void buildSauce() { pizza.setSauce("mild"); } public void buildToppings() { pizza.setToppings("ham+pineapple"); }

Cook class Cook { private PizzaBuilder pizzaBuilder; public void setPizzaBuilder(PizzaBuilder pb) { pizzaBuilder = pb; } public Pizza getPizza() { return pizzaBuilder.getPizza(); } public void constructPizza() { pizzaBuilder.createNewPizzaProduct(); pizzaBuilder.buildDough(); pizzaBuilder.buildSauce(); pizzaBuilder.buildToppings(); }

BuilderExample class BuilderExample { public static void main(String[] args) { Cook cook = Cook.new(); HawaiianPizzaBuilder hawaiianBuilder = new HawaiianPizzaBuilder(); SpicyPizzaBuilder spicyBuilder = new SpicyPizzaBuilder(); Pizza hawaiianPizza; Pizza spicyPizza; cook.setPizzaBuilder(hawaiianBuilder); cook.constructPizza(); hawaiianPizza = cook.getPizza(); cook.setPizzaBuilder(spicyBuilder); cook.constructPizza(); spicyPizza = cook.getPizza(); }

Why this over factory pattern?  Individual steps may not be used  Hold the pickles, extra mustard

Sources  

MEDIATOR DESIGN PATTERN

Overview of Mediator  Defines an object that manages how a set of objects interact  Objects interact with the mediator object rather than with each other

Real World Example

Diagram

Advantages  Reduces coupling in situations when many objects need to communicate  Minimizes “spaghetti code” by localizing the communication process to just one class

Disadvantages  Easy for mediators to become complex in practice

DECORATOR PATTERN Raul Aragonez

Intent  Attach additional responsibilities to an object dynamically.  Decorators provide a flexible alternative to subclassing for extending functionality.  Client-specified embellishment of a core object by recursively wrapping it.

UML Diagram

Participants  Component: defines the interface for objects that can have responsibilities added to them dynamically.  Concrete Component: is the object that can be decorated. It is defined so that zero or more responsibilities can be attached to it.  Decorator: maintains a reference to a Component object an interface that conforms to Component's interface.  Concrete Decorator: wraps around the Concrete Component and adds functionality to it.

Pizza Example

Class Explosion

Instead…

Advantages  Responsibilities can be added to one object without affecting the rest of the objects in the class.  Contents of the object are not affected and Responsibilities can be removed as easily as they are added.  Lots of Features = slow system performance = unnecessary code we need to support. We are paying for features that we don't need!  Therefore, Decorator lets us add features and responsibilities as we need them at run-time.

Pizza example Renovation

Lets try it!

Disadvantages  Lots of little objects  As a system gets larger it would become composed of many little objects that look the same, decorator objects. This makes it hard to learn the system and debug the code.  Maintenance of the Decorator code  when adding functionality to an object, there is no need to know the interface of the Decorator class. The Decorator must conform to the interface of the object. This means that there's always the need to maintain the interface to keep it synchronized with the object interface.

Sources   or or  03.pdf 03.pdf  04/decorator_paper.html#intent 04/decorator_paper.html#intent