Decorator Design Pattern

Slides:



Advertisements
Similar presentations
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Advertisements

Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Client/Server Software Architectures Yonglei Tao.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Façade Design Pattern (1) –A structural design pattern.
Composite Design Pattern. Motivation – Dynamic Structure.
Design Patterns.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
SOFTWARE DESIGN AND ARCHITECTURE
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Design Patterns: Structural Design Patterns
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
The Façade Pattern SE-2811 Dr. Mark L. Hornick 1.
Structural Design Patterns
ECE450S – Software Engineering II
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
Design Patterns Structural Patterns. Adapter Convert the interface of a class into another interface clients expect Adapter lets classes work together.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Secure middleware patterns E.B.Fernandez. Middleware security Architectures have been studied and several patterns exist Security aspects have not been.
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.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
S.Ducasse Stéphane Ducasse 1 Decorator.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Abstract Factory Pattern
Design Patterns Spring 2017.
N-Tier Architecture.
Façade Pattern:.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Factory Patterns 1.
Behavioral Design Patterns
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Abstract Factory Pattern
#01 Client/Server Computing
Intent (Thanks to Jim Fawcett for the slides)
Ch > 28.4.
More Design Patterns 1.
Design Patterns Satya Puvvada Satya Puvvada.
More Design Patterns 1.
Inventory of Distributed Computing Concepts and Web services
Decorator Pattern Intent
Jim Fawcett CSE776 – Design Patterns Summer 2003
Object Oriented Design Patterns - Structural Patterns
UNIT-III Structural Design Patterns
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
10. Façade Pattern SE2811 Software Component Design
Software Design Lecture : 35.
Informatics 122 Software Design II
Database System Architectures
defines a higher-level interface that makes a subsystem easier to use
#01 Client/Server Computing
Presentation transcript:

Decorator Design Pattern Objective: Want to add attributes to an object Number of attribute to add is unspecified One should be able to easily add newly defined attributes to code with minimal change Don’t want a massive explosion in the number of subclasses employed

What a mess!!

Basic Idea Reify (convert into or regard as a concrete thing) each attribute making it a fully fledged object Treat the object and its attributes as a composite object using the composite design pattern Extend the functionality for the object to operate on the tree instead of the node

Advantages Provides an alternative to sub classing Decorators change behaviour of their component by adding functionality before, after or in place of method calls to their child/children. A component can have any number of decorators Decorators can add state to the thing decorated Presence of decorators are typically transparent Only have to change cost of cream cheese in the cream cheese decorator, no matter how used

Decorator Definition A decorator attaches additional responsibilities to an object dynamically A decorator provide a flexible alternative to sub classing for extending functionality Caution: Decorators can result in many small objects in the design and overuse may be complicated and inefficient or somewhat limiting

Facade Intent: “Provide a unified, higher-level, interface to a whole module making it easier to use.” Motivation: Composing classes into subsystems reduces complexity. Using a Facade minimizes the communication dependencies between subsystems. Applicability: When you want a simple interface to a complex subsystem. There are many dependencies between clients and a subsystem. You want to layer your subsystems.

Facade Design Pattern Provides a simplified interface to an otherwise difficult to use subsystem Does not exclude direct access to the components of the subsystem But makes life easier for the clients who have a canned set of actions they wish to always perform on the subsystem Permits these clients to know nothing about the real subsystem

Facade [en.wikipedia.org]

Components of the subsystem may remain open for direct usage A subsystem may have many facades

Facade Participants: Collaborations: Consequences: Facade Subsystem classes Collaborations: Clients interact subsystem via Facade. Consequences: Shields clients from subsystem components. Promotes weak coupling. (strong within subsystem, weak between them) Does not prevent access to subsystem classes.

Adapter vs Facade The main difference between two is their intent: Adapter: Change an interface so it matches the one the client needs Facade: Provide a client with a simplified interface to a subsystem

Flyweight Design Pattern Have lots of the same objects but each with a small amount of differing state Don’t want to have to allocate space for all these objects Extract what changes from what does not Client object contains the changing state Invokes methods of flyweight providing state as parameter Flyweight is stateless permitting sharing/reuse State can be stored in array, on disk, in database

Front Controller Design Pattern Route code through a common front end controller which handles task that must be performed on absolutely every access. Eg. Security Unmarshalling of web parameters Deciding which script to be invoked Logging of requests received Load balancing ..

Advantages Avoids having to repeat code in many places But could alternatively put this code in procedures Centralises routing and so isolates low level logic from the “what do I can next” question A component should do one thing Simplifies navigation issues Reconfiguring order of page presentation easier Can spawn thread for bulk of work Can preserve Javascript state on client

Proxy Design Pattern Provides a surrogate or placeholder for another object to control access to it. Uses Remote: transparent communication with object Virtual: creates real object only when needed Side effects while loading might include wait warning Protection: refuses access unless permitted Stub generation in RPC etc.