Design Patterns. Decorator. Oliver Haase

Size: px
Start display at page:

Download "Design Patterns. Decorator. Oliver Haase"

Transcription

1 Design Patterns Decorator Oliver Haase 1

2 Motivation Your task is to program a coffee machine. The machine brews plain coffee, coffee with cream, sugar, sweetener, and cinnamon. A plain coffee costs 0,90, cream costs 0,20, sugar 0,10, sweetener 0,10, cinnamon 0,05. A plain coffee has zero calories, a portion of cream adds 10 calories, a portion of sugar 20 calories, both sweetener and cinnamon don't add any calories. All extras can be combined with each other. Model the coffee entity (entities) such that it can be asked for its configuration, its price, and its calories. 2

3 Option 1 - Class Explosion 3 Coffee CoffeeWith Cream CoffeeWith Sugar CoffeeWith Sweetener CoffeeWith Cinammon CoffeeWith CreamAnd Sugar CoffeeWith CreamAnd Sweetener CoffeeWith CreamAnd Cinammon CoffeeWith SugarAnd Cinammon CoffeeWith SweetenerAnd Cinammon CoffeeWith SugarAnd Sweetener CoffeeWith CreamAnd SugarAnd Sweetener CoffeeWith CreamAnd SugarAnd Cinammon CoffeeWith CreamAnd SweetenerAnd Cinammon CoffeeWith CreamAnd SugarAnd SweetenerAnd Cinammon

4 Option 1 - Class Explosion What if extras can be added more than once (e.g. double cream, double sugar)? Option 1 becomes not only messy, but impossible! 4

5 Option 2 - Attributed Coffee Coffee cream: int sugar: int sweetener: int cinammon: int getprice() getcalories() tostring() cream * sugar * sweetener * cinammon * 0.05 cream * 10 + sugar * 20 String result = "coffee" for ( int i = 0; i < cream; i++) result += " cream";... 5

6 Option 2 - Attributed Coffee What if new extra is to be offered, e.g. sprinkles for 0,30 and 5 calories? Class Coffee needs to be modified. 6

7 Option 3 - Decorated Coffee Coffee getprice() getcalories() tostring() PlainCoffee getprice() getcalories() tostring() "Coffee" CoffeeDecorator component getprice() getcalories() tostring() component.getprice() component.getcalories() component.tostring() CreamDecorator getprice() getcalories() tostring() SugarDecorator getprice() getcalories() tostring() SweetenerDecorator getprice() getcalories() tostring() CinammonDecorator getprice() getcalories() tostring() super.getprice() super.getcalories() + 10 super.tostring() + "Cream" 7

8 Option 3 - Decorated Coffee Sample coffee instantiation: Coffee cupofcoffee = new SugarDecorator( new CreamDecorator( new CreamDecorator( new PlainCoffee()))); Resulting object diagram: cupofcoffee: SugarDecorator component :CreamDecorator component :CreamDecorator component : PlainCoffee 8

9 Option 3 - Decorated Coffee Sample sequence diagram for a getprice call: cupofcoffee: SugarDecorator :CreamDecorator :CreamDecorator : PlainCoffee getprice() getprice() getprice() getprice()

10 Decorator - Structure interface through which clients access (decorated) component Client ConreteComponent operation() plain component that can be decorated Component operation() Decorator component operation() maintains reference to decorated component defines same interface as Component delegates operation calls to decorated component component.operation() ConcreteDecoratorA operation() ConcreteDecoratorB operation() adds its own functionality to decorated component super.operation() own additional functionality 10

11 Pros & Cons Pros Simple, non-intrusive introduction of new decorators objects can be (re-)decorated at runtime in contrast to option 1: class explosion different functionality for different object variants through polymorphism and chaining rather than conditional statements (option 2: object with attributes) object can be decorated with same decorator multiple times 11

12 Pros & Cons Cons multiply decorated object represented by multiple runtime objects runtime penalty, higher complexity, e.g., w.r.t. debugging component and its decorator are not the same object object identity gets lost 12

13 Application Concurrency 1: Assume a non-threadsafe implementation of a mutable pair: public interface MutablePair<E1, E2> { } E1 getleft(); E2 getright(); void setleft(e1 left); void setright(e2 right); void update(e1 left, E2 public class NotThreadSafePair<E1, E2> implements MutablePair<E1, E2> { private E1 left; private E2 right; public NotThreadSafePair(E1 left, E2 right) { this.left = left; } this.right = right; 13

14 public E1 getleft() { return left; public E2 getright() { return right; public void setleft(e1 left) { this.left = left; public void setright(e2 right) { this.right = right; public void update(e1 left, E2 right) { } this.left = left; this.right = right; public String tostring() { return "NotThreadSafePair(" + left + ", " + right + ")"; } 14

15 Application Encapsulate not-threadsafe object with a threadsafe public class ThreadSafePair<E1, E2> implements MutablePair<E1, E2> { private MutablePair<E1, E2> delegate; public ThreadSafePair(E1 left, E2 right) { } delegate = new NotThreadSafePair(left, public synchronized E1 getleft() { } return public synchronized E2 getright() { } return delegate.getright(); 15

16 public synchronized void setleft(e1 left) { } public synchronized void setright(e2 right) { } public synchronized void update(e1 left, E2 right) { delegate.update(left, right): public synchronized String tostring() { return "ThreadSafePair(" + left + ", " + right + ")"; } Object confinement thru Java monitor pattern see: Collections.synchronizedCollection(), Collections.synchronizedList(), etc. 16

17 Application Concurrency 2: Read-only decorators for collections Collections.unmodifiable[Set Map Collection]: static factory methods that wrap backing collection read operations are passed to backing collection modifying operations return UnsupportedOperationException 17

18 Related Patterns Adapter: An adapter modifies the adapted object's interface; a decorator adds functionality to an object without extending its interface. 18

19 Related Patterns Proxy vs Decorator: Client Subject operation() Client Component operation() ConreteComponent operation() Decorator component operation() component.operation() Proxy delegate operation() RealSubject operation() ConcreteDecoratorA operation() ConcreteDecoratorB operation() delegate.operation() super.operation() own additional functionality 19

20 Related Patterns Proxy vs Decorator: Similar structure: both involve a wrapper object that references the real subject But: there is only one proxy, as opposed to many decorators for a single object Different purpose: proxy controls access to subject, while decorator changes component's functionality 20

21 Flyweight 21

22 Motivation Imagine a text processor that represents text documents consisting of pages, rows, words, and characters. For homogeneity, it would be nice to treat the concepts of pages, rows, words, and characters similarly, in particular as objects. Problem: A book with 300 pages can easily contain characters huge overhead if modeled as objects! 22

23 Idea Divide object state into intrinsic and extrinsic state, such that there is only a small number of distinct objects with different intrinsic states. Share these flyweight objects. Feed flyweight objects with extrinsic state for operation invocations. 23

24 Example Character Flyweight Objects intrinsic state: extrinsic state: character code (e.g. Unicode) font, text style (bold, italics, regular), position 24

25 Applicability Use the flyweight pattern only if all of the following apply: An application uses a large number of objects. The memory consumption forbids instantiation of individual objects. A big part of the object state can be moved into the context (can be made extrinsic). Removal of the extrinsic state results in a small number of distinct objects. The application does not depend on the object identity. 25

26 Structure creates and maintains flyweight objects declares operations that get fed with the extrinsic state some implementations of Flyweight might not be shared - these may contain complete state implements the flyweight interface keeps intrinsic state of the shared object has reference to flyweight objects keeps or computes objects extrinsic state 26

27 Interactions Intrinsic and extrinsic state must be clearly distinguishable. Flyweight objects store intrinsic state, clients store or compute extrinsic state and supply it into flyweights' operations. Clients don't create flyweight objects directly. A flyweight factory makes sure flyweight objects are correctly shared. 27

28 Consequences Reduced memory consumption comes at the cost of increased runtime, because client has to compute or access stored extrinsic state information, and pass it into flyweight objects. Memory saving depends on degree of reduction of objects; size of intrinsic state; whether extrinsic state is stored or calculated. 28

29 Extrinsic State Applicability depends on how easily extrinsic state information can be identified and pulled out. Benefit (in terms of memory consumption) depends on whether the amount of extrinsic state for all flyweight objects is less than the original state information. This is the case, if extrinsic state can be computed; is equal for groups of objects. Example character flyweight objects: intrinsic state: Character code (e.g. Unicode) extrinsic state: font, text style, position Client doesn't have to store font and text style per flyweight object, but stores these attributes per bigger chunks of text. 29

30 Related Patterns Flyweight often combined with Composite pattern, to build hierarchy of objects with shared (flyweight) leaves. State and Strategy objects are preferably implemented as flyweight objects. 30

31 Closing Remarks Usually, patterns are intended to keep design simply, to reduce dependencies, to reduce number of classes, etc. simplicity, clarity, maintainability, & friends sometimes - though not always - at the expense of reduced efficiency In contrast, flyweight pattern motivated by efficiency considerations relevance can be expected to decrease as main memory continuously gets cheaper 31

32 Composite 32

33 Motivation Imagine a GUI class library that consists of graphical elements, such as buttons, labels, textboxes, etc. These graphical elements can be grouped and structured in graphical containers. A particular GUI might consist of deeply nested graphical containers and elements. For practical purposes it would, however, be comfortable to be able to treat all graphical components, i.e. containers and elements, the same. E.g. both containers and elements should be able to be asked to paint or scale themselves. 33

34 Idea Define a common supertype GraphicalComponent for both graphical containers and graphical elements; this supertype defines operations on the elements (paint, scale); 34

35 Structure - Example Client GraphicalComponent paint() scale() Textbox paint() scale() Button paint() scale() Label paint() scale() Container components paint() scale() add(graphcomp) remove(graphcomp) getchild(int) for each comp in components comp.paint() for each comp in components comp.scale() 35

36 Sample Run-Time Object Graph :Container components :Container components : Label : Textbox : Label : Button 36

37 General Structure manipulates objects of composite structure thru component interface declares interface for all objects of the nested structure might provide default implementation might define and optionally implement an operation to access an object's parent Client Component operation() defines behavior of complex objects that can contain children stores references to children defines child management operations Leaf operation() represents and defines behavior of primitive objects Composite children operation() add(component) remove(component) getchild(int) for each child in children child.operation() 37

38 Run-Time Object Graph, 2nd :Composite children :Composite children : Leaf : Leaf : Leaf : Leaf 38

39 Applicability Use the composite pattern if you want to model a whole-part-relationship; be able to treat aggregate and atomic objects the same. 39

40 Interactions Clients use the Component interface to interact with objects in the structure. If the target is a primitive object, an operation call is handled directly. If it is a composite, then the composite delegates the call to its children. It might do some extra work before or after the delegation. 40

41 Consequences Composite patterns simplifies clients because they don't need to distinguish between primitive and complex objects New composite and leaf types can be added easily without modifications of the client code Might be too general, if certain composite types should only contain certain leave types leads to explicit type checks at run-time. 41

42 Child Management Operations Two basic options as to where to define operations to manage child objects (add, remove, getchild): 1.In Composite class, as seen more type safety, i.e. client cannot try to add or remove children to primitive object less transparency, i.e. client needs to distinguish between primitive and composite objects when executing childrenrelated operations 2.In Component class, as described by GoF possible default implementation: noop, exception complete transparency, i.e. client can treat primitive and composite objects the same 42

43 Alternative General Structure Client Component operation() add(component) remove(component) getchild(int) Leaf operation() Composite children operation() add(component) remove(component) getchild(int) for each child in children child.operation() 43

44 Reference to Parent Object Operation to access an object's parent can simplify traversal of the composite structure. Where to be modeled? Component How to make sure all children of an object have that object as parent? set children's parent reference only in add and remove operations of class Composite. 44

45 Related Patterns Chain of Responsibility: Reference to parent object often used to implement a chain of responsibility. Flyweight can be used to share components. In that case, references to parent objects don't make sense. Iterator can be used to access all components of a composite structure one by one. Visitor can be used to traverse the structure and perform operations on individual elements. 45

46 Related Patterns Decorator: can technically be regarded degenerated Composite with a decorator containing only one object, and a Composite containing many objects. different purpose: Decorator adds functionality to same logical object, Composite models whole-part-relationship. 46

47 Facade 47

48 Purpose Provides a homogeneous interface to a set of interfaces of a subsystem. Simplifies usability of the subsystem. 48

49 Motivation 49

50 Motivation 50

51 Motivation Problem: Client has to know a lot of classes / interfaces to simply watch a movie many dependencies, tight coupling, hard to change home theater configuration without the need to change all clients 51

52 Motivation 52

53 Description Applicability: Use the facade pattern to hide a subsystem's internal complexity and provide a simplified interface to clients. Systems tend to grow over time, design patterns tend to increase the number of classes. A facade shields clients from that complexity. loosen coupling between the subsystem and clients. A facade removes dependencies from the actual subsystem classes. build multi-layered architectures, separated through one facade per layer as the entry point for the next higher layer. 53

54 Structure knows which subsystem classes are responsible for which requests delegates client requests to respective subsystem objects implements subsystem functionality executes requests from the facade doesn t know facade (doesn t have reference to facade) strict layering 54

55 Interactions Clients use the subsystem by sending requests to the facade. The facade forwards the request to the responsible subsystem objects(s). One client request might well lead to several subsystem requests. Even though the subsystem functionality is implemented in the subsystem, the facade might fill in some logic to orchestrate the lower level requests. Clients that use the facade don't have to use the subsystem directly. 55

56 Comparison of the Structural Patterns 56

57 Circle of Structural Patterns 57

58 Circle of Structural Patterns 58

59 Adapter vs. Bridge Commonalities: Level of indirection for the access to the actual object Delegation from an interface that the actual object doesn't provide 59

60 Adapter vs. Bridge Differences: Purpose: Adapter intends to match an implementation with a (different) interface Bridge intends to separate implementation from abstract to enable both to evolve separately Time of application: Adapter is employed rather later, i.e. when two existing types need to be brought together Bridge is employed early, to foresee separate evolution of abstraction and implementation 60

61 Composite vs. Decorator Commonalities: Structures of composite and decorator very similar (both use recursion to structure hierarchies of objects) Decorator structure might be mistaken for degenerated composite structure composite builds tree, decorator builds chain of objects 61

62 Composite vs. Decorator Differences are in their purpose: Decorator intends to add functionality to a type without changing it avoids exponential explosion of number of classes Composite intents to treat leaves and inner nodes (container objects) of an object hierarchy homogeneously 62

63 Proxy vs. Decorator Commonalities: Similar structures, in both cases indirect access to actual object via upstream object in both cases, upstream object maintains reference to actual object (subject) and delegates requests to it 63

64 Proxy vs. Decorator Differences are in their purpose: Proxy is not about adding functionality, but about avoiding direct access to the subject, for varying reasons (protection, efficiency, transparent remote access) With proxy pattern, subject implements key functionality, with decorator pattern, functionality is split across levels of indirection. 64

Composite Pattern. IV.4 Structural Pattern

Composite Pattern. IV.4 Structural Pattern IV.4 Structural Pattern Motivation: Compose objects to realize new functionality Flexible structures that can be changed at run-time Problems: Fixed class for every composition is required at compile-time

More information

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005 1 Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/6448 - Spring Semester, 2005 2 Last Lecture Design Patterns Background and Core Concepts Examples

More information

Object-Oriented Oriented Programming

Object-Oriented Oriented Programming Object-Oriented Oriented Programming Composite Pattern CSIE Department, NTUT Woei-Kae Chen Catalog of Design patterns Creational patterns Abstract Factory, Builder, Factory Method, Prototype, Singleton

More information

Last Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns

Last Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns Lecture 26: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Last Lecture Design Patterns Background and Core Concepts Examples Singleton,

More information

Design Patterns IV Structural Design Patterns, 1

Design Patterns IV Structural Design Patterns, 1 Structural Design Patterns, 1 COMP2110/2510 Software Design Software Design for SE September 17, 2008 Class Object Department of Computer Science The Australian National University 18.1 1 2 Class Object

More information

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 9 OO modeling Design Patterns Structural Patterns Behavioural Patterns

More information

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester Design Patterns Comp2110 Software Design Department of Computer Science Australian National University Second Semester 2005 1 Design Pattern Space Creational patterns Deal with initializing and configuring

More information

SDC Design patterns GoF

SDC Design patterns GoF SDC Design patterns GoF Design Patterns The design pattern concept can be viewed as an abstraction of imitating useful parts of other software products. The design pattern is a description of communicating

More information

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns Structural Design Patterns, 1 1 COMP2110/2510 Software Design Software Design for SE September 17, 2008 2 3 Department of Computer Science The Australian National University 4 18.1 18.2 GoF Structural

More information

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS LOGISTICS HW3 due today HW4 due in two weeks 2 IN CLASS EXERCISE What's a software design problem you've solved from an idea you learned from someone else?

More information

Design Patterns Reid Holmes

Design Patterns Reid Holmes Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns Reid Holmes GoF design patterns $ %!!!! $ "! # & Pattern vocabulary Shared vocabulary

More information

The Composite Design Pattern

The Composite Design Pattern Dr. Michael Eichberg Software Technology Group Department of Computer Science Technische Universität Darmstadt Introduction to Software Engineering The Composite Design Pattern For details see Gamma et

More information

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern Think of drawing/diagramming editors ECE450 Software Engineering II Drawing/diagramming editors let users build complex diagrams out of simple components The user can group components to form larger components......which

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Composite 1 Composite pattern Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects

More information

Design Pattern: Composite

Design Pattern: Composite Design Pattern: Composite Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Motivation

More information

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and

More information

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of Computer Science Technische Universität Darmstadt Dr.

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Composite 1 Composite pattern Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects

More information

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns EPL 603 TOPICS IN SOFTWARE ENGINEERING Lab 6: Design Patterns Links to Design Pattern Material 1 http://www.oodesign.com/ http://www.vincehuston.org/dp/patterns_quiz.html Types of Design Patterns 2 Creational

More information

Design Patterns V Structural Design Patterns, 2

Design Patterns V Structural Design Patterns, 2 Structural Design Patterns, 2 COMP2110/2510 Software Design Software Design for SE September 17, 2008 Department of Computer Science The Australian National University 19.1 1 2 Formal 3 Formal 4 Formal

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Composite 1 Composite pattern Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects

More information

Adapter pattern. Acknowledgement: Freeman & Freeman

Adapter pattern. Acknowledgement: Freeman & Freeman Adapter pattern Acknowledgement: Freeman & Freeman Example Scenario The European wall outlet exposes one interface for getting power The adapter converts one interface into another The US laptop expects

More information

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference 2015-2016 Visitor See lecture on design patterns Design of Software Systems 2 Composite See lecture on design patterns

More information

The Composite Pattern

The Composite Pattern The Composite Pattern Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. This is called

More information

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool Design Patterns What are Design Patterns? What are Design Patterns? Why Patterns? Canonical Cataloging Other Design Patterns Books: Freeman, Eric and Elisabeth Freeman with Kathy Sierra and Bert Bates.

More information

Design Patterns Reid Holmes

Design Patterns Reid Holmes Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns Reid Holmes GoF design patterns $ %!!!! $ "! # & Pattern vocabulary Shared vocabulary

More information

The Strategy Pattern Design Principle: Design Principle: Design Principle:

The Strategy Pattern Design Principle: Design Principle: Design Principle: Strategy Pattern The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Design

More information

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1 What is a Design Pattern? Each pattern Describes a problem which occurs over and over again in our environment,and then describes the core of the problem Novelists, playwrights and other writers rarely

More information

CSE 70 Final Exam Fall 2009

CSE 70 Final Exam Fall 2009 Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15

More information

COSC 3351 Software Design. Design Patterns Structural Patterns (I)

COSC 3351 Software Design. Design Patterns Structural Patterns (I) COSC 3351 Software Design Design Patterns Structural Patterns (I) Spring 2008 Purpose Creational Structural Behavioral Scope Class Factory Method Adaptor(class) Interpreter Template Method Object Abstract

More information

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship CSCI 253 Object Oriented Design: Iterator Pattern George Blankenship George Blankenship 1 Creational Patterns Singleton Abstract factory Factory Method Prototype Builder Overview Structural Patterns Composite

More information

Design Patterns in C++

Design Patterns in C++ Design Patterns in C++ Structural Patterns Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa March 23, 2011 G. Lipari (Scuola Superiore Sant Anna) Structural patterns March

More information

Topics in Object-Oriented Design Patterns

Topics in Object-Oriented Design Patterns Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;

More information

A Reconnaissance on Design Patterns

A Reconnaissance on Design Patterns A Reconnaissance on Design Patterns M.Chaithanya Varma Student of computer science engineering, Sree Vidhyanikethan Engineering college, Tirupati, India ABSTRACT: In past decade, design patterns have been

More information

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011 Design Patterns Lecture 1 Manuel Mastrofini Systems Engineering and Web Services University of Rome Tor Vergata June 2011 Definition A pattern is a reusable solution to a commonly occurring problem within

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecture 14: Design Workflow Department of Computer Engineering Sharif University of Technology 1 UP iterations and workflow Workflows Requirements Analysis Phases Inception Elaboration

More information

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod Principles of Software Construction: Objects, Design, and Concurrency Assigning Responsibilities to Objects toad Fall 2014 Jonathan Aldrich Charlie Garrod School of Computer Science Key concepts from Thursday

More information

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and

More information

Software Eningeering. Lecture 9 Design Patterns 2

Software Eningeering. Lecture 9 Design Patterns 2 Software Eningeering Lecture 9 Design Patterns 2 Patterns covered Creational Abstract Factory, Builder, Factory Method, Prototype, Singleton Structural Adapter, Bridge, Composite, Decorator, Facade, Flyweight,

More information

Design Patterns Lecture 2

Design Patterns Lecture 2 Design Patterns Lecture 2 Josef Hallberg josef.hallberg@ltu.se 1 Patterns covered Creational Abstract Factory, Builder, Factory Method, Prototype, Singleton Structural Adapter, Bridge, Composite, Decorator,

More information

administrivia today UML start design patterns Tuesday, September 28, 2010

administrivia today UML start design patterns Tuesday, September 28, 2010 administrivia Assignment 2? promise to get past assignment 1 back soon exam on monday review slides are posted your responsibility to review covers through last week today UML start design patterns 1 Unified

More information

Design patterns. OOD Lecture 6

Design patterns. OOD Lecture 6 Design patterns OOD Lecture 6 Next lecture Monday, Oct 1, at 1:15 pm, in 1311 Remember that the poster sessions are in two days Thursday, Sep 27 1:15 or 3:15 pm (check which with your TA) Room 2244 + 2245

More information

COSC 3351 Software Design. Design Patterns Structural Patterns (II) Edgar Gabriel. Spring Decorator

COSC 3351 Software Design. Design Patterns Structural Patterns (II) Edgar Gabriel. Spring Decorator COSC 3351 Software Design Design Patterns Structural Patterns (II) Spring 2008 Decorator Allows to add responsibilities to objects dynamically without subclassing Objects are nested within another Each

More information

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011 Design Patterns Lecture 2 Manuel Mastrofini Systems Engineering and Web Services University of Rome Tor Vergata June 2011 Structural patterns Part 2 Decorator Intent: It attaches additional responsibilities

More information

Design Patterns. An introduction

Design Patterns. An introduction Design Patterns An introduction Introduction Designing object-oriented software is hard, and designing reusable object-oriented software is even harder. Your design should be specific to the problem at

More information

The GoF Design Patterns Reference

The GoF Design Patterns Reference The GoF Design Patterns Reference Version.0 / 0.0.07 / Printed.0.07 Copyright 0-07 wsdesign. All rights reserved. The GoF Design Patterns Reference ii Table of Contents Preface... viii I. Introduction....

More information

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar Design Patterns MSc in Communications Software Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

1 Software Architecture

1 Software Architecture Some buzzwords and acronyms for today Software architecture Design pattern Separation of concerns Single responsibility principle Keep it simple, stupid (KISS) Don t repeat yourself (DRY) Don t talk to

More information

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

OODP Session 4.   Web Page:   Visiting Hours: Tuesday 17:00 to 19:00 OODP Session 4 Session times PT group 1 Monday 18:00 21:00 room: Malet 403 PT group 2 Thursday 18:00 21:00 room: Malet 407 FT Tuesday 13:30 17:00 room: Malet 404 Email: oded@dcs.bbk.ac.uk Web Page: http://www.dcs.bbk.ac.uk/~oded

More information

CS342: Software Design. November 21, 2017

CS342: Software Design. November 21, 2017 CS342: Software Design November 21, 2017 Runnable interface: create threading object Thread is a flow of control within a program Thread vs. process All execution in Java is associated with a Thread object.

More information

Design Patterns Revisited

Design Patterns Revisited CSC 7322 : Object Oriented Development J Paul Gibson, A207 paul.gibson@int-edu.eu http://www-public.it-sudparis.eu/~gibson/teaching/csc7322/ Design Patterns Revisited /~gibson/teaching/csc7322/l13-designpatterns-2.pdf

More information

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

Design Patterns. SE3A04 Tutorial. Jason Jaskolka SE3A04 Tutorial Jason Jaskolka Department of Computing and Software Faculty of Engineering McMaster University Hamilton, Ontario, Canada jaskolj@mcmaster.ca November 18/19, 2014 Jason Jaskolka 1 / 35 1

More information

Introduction to Software Engineering: Object Design I Reuse & Patterns

Introduction to Software Engineering: Object Design I Reuse & Patterns Introduction to Software Engineering: Object Design I Reuse & Patterns John T. Bell Department of Computer Science University of Illinois, Chicago Based on materials from Bruegge & DuToit 3e, Chapter 8,

More information

Application Architectures, Design Patterns

Application Architectures, Design Patterns Application Architectures, Design Patterns Martin Ledvinka martin.ledvinka@fel.cvut.cz Winter Term 2017 Martin Ledvinka (martin.ledvinka@fel.cvut.cz) Application Architectures, Design Patterns Winter Term

More information

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and

More information

2.1 Design Patterns and Architecture (continued)

2.1 Design Patterns and Architecture (continued) MBSE - 2.1 Design Patterns and Architecture 1 2.1 Design Patterns and Architecture (continued) 1. Introduction 2. Model Construction 2.1 Design Patterns and Architecture 2.2 State Machines 2.3 Timed Automata

More information

2.1 Design Patterns and Architecture (continued)

2.1 Design Patterns and Architecture (continued) MBSE - 2.1 Design Patterns and Architecture 1 2.1 Design Patterns and Architecture (continued) 1. Introduction 2. Model Construction 2.1 Design Patterns and Architecture 2.2 State Machines 2.3 Abstract

More information

Design Patterns (Facade, Composite)

Design Patterns (Facade, Composite) CS 247: Software Engineering Principles Design Patterns (Facade, Composite) Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch 7 Adapter and Facade patterns

More information

Design Patterns. Definition of a Design Pattern

Design Patterns. Definition of a Design Pattern Design Patterns Barbara Russo Definition of a Design Pattern A Pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem,

More information

Tuesday, October 4. Announcements

Tuesday, October 4. Announcements Tuesday, October 4 Announcements www.singularsource.net Donate to my short story contest UCI Delta Sigma Pi Accepts business and ICS students See Facebook page for details Slide 2 1 Design Patterns Design

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Design Patterns (Composite)

Design Patterns (Composite) CS 247: Software Engineering Principles Design Patterns (Composite) Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch 9: Composite and Iterator Patterns

More information

A few important patterns and their connections

A few important patterns and their connections A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Plan Singleton Factory method Facade and how they are connected. You should understand how to

More information

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade Plan A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Singleton Factory method Facade and how they are connected. You should understand how to

More information

The Design Patterns Matrix From Analysis to Implementation

The Design Patterns Matrix From Analysis to Implementation The Design Patterns Matrix From Analysis to Implementation This is an excerpt from Shalloway, Alan and James R. Trott. Design Patterns Explained: A New Perspective for Object-Oriented Design. Addison-Wesley

More information

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University Idioms and Design Patterns Martin Skogevall IDE, Mälardalen University 2005-04-07 Acronyms Object Oriented Analysis and Design (OOAD) Object Oriented Programming (OOD Software Design Patterns (SDP) Gang

More information

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve? Plan Design principles: laughing in the face of change Perdita Stevens School of Informatics University of Edinburgh What are we trying to achieve? Review: Design principles you know from Inf2C-SE Going

More information

Design Patterns. Command. Oliver Haase

Design Patterns. Command. Oliver Haase Design Patterns Command Oliver Haase 1 Description Purpose: Encapsulate a command as an object. Allows to dynamically configure an invoker with a command object. Invoker can invoke command without knowing

More information

The Adapter Pattern. Interface with anything!

The Adapter Pattern. Interface with anything! The Adapter Pattern Interface with anything! Adapter in a Nutshell - An adapter takes an object with one interface, and changes the interface to make it look like something it s not. - Allows two objects

More information

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns Overview CS 2704 Topic: Design Patterns Design pattern concepts Kinds of patterns Some specific patterns Pattern resources 5/1/00 CS2704 Design Patterns 2 Design Pattern Solution to a particular kind of

More information

Design Patterns. Structural Patterns. Oliver Haase

Design Patterns. Structural Patterns. Oliver Haase Design Patterns Structural Patterns Oliver Haase 1 Purpose Structural patterns describe how to compose classes (incl. interfaces) and objects to get larger structures. Class based structural patterns use

More information

Introduction and History

Introduction and History Pieter van den Hombergh Fontys Hogeschool voor Techniek en Logistiek September 15, 2016 Content /FHTenL September 15, 2016 2/28 The idea is quite old, although rather young in SE. Keep up a roof. /FHTenL

More information

CISC 322 Software Architecture

CISC 322 Software Architecture CISC 322 Software Architecture Lecture 14: Design Patterns Emad Shihab Material drawn from [Gamma95, Coplien95] Slides adapted from Spiros Mancoridis and Ahmed E. Hassan Motivation Good designers know

More information

Design Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles

Design Patterns. Gang of Four* Design Patterns. Gang of Four Design Patterns. Design Pattern. CS 247: Software Engineering Principles CS 247: Software Engineering Principles Design Patterns Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch Strategy Pattern Ch 7 Adapter and Facade patterns

More information

CS 247: Software Engineering Principles. Design Patterns

CS 247: Software Engineering Principles. Design Patterns CS 247: Software Engineering Principles Design Patterns Reading: Freeman, Robson, Bates, Sierra, Head First Design Patterns, O'Reilly Media, Inc. 2004 Ch 1 Strategy Pattern Ch 7 Adapter and Facade patterns

More information

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar Design Patterns MSc in Communications Software Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

C++ for System Developers with Design Pattern

C++ for System Developers with Design Pattern C++ for System Developers with Design Pattern Introduction: This course introduces the C++ language for use on real time and embedded applications. The first part of the course focuses on the language

More information

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar Design Patterns MSc in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout 1 Last update: 2 November 2004 Trusted Components Reuse, Contracts and Patterns Prof. Dr. Bertrand Meyer Dr. Karine Arnout 2 Lecture 5: Design patterns Agenda for today 3 Overview Benefits of patterns

More information

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8 Object Oriented Methods with UML Introduction to Design Patterns- Lecture 8 Topics(03/05/16) Design Patterns Design Pattern In software engineering, a design pattern is a general repeatable solution to

More information

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004 Facade and Adapter Comp-303 : Programming Techniques Lecture 19 Alexandre Denault Computer Science McGill University Winter 2004 March 23, 2004 Lecture 19 Comp 303 : Facade and Adapter Page 1 Last lecture...

More information

Design Patterns. State. Oliver Haase

Design Patterns. State. Oliver Haase Design Patterns State Oliver Haase 1 Description Object based behavioral pattern Purpose: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

More information

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator. Comparative Study In Utilization Of Creational And Structural Design Patterns In Solving Design Problems K.Wseem Abrar M.Tech., Student, Dept. of CSE, Amina Institute of Technology, Shamirpet, Hyderabad

More information

Object Design II: Design Patterns

Object Design II: Design Patterns Object-Oriented Software Engineering Using UML, Patterns, and Java Object Design II: Design Patterns Bernd Bruegge Applied Software Engineering Technische Universitaet Muenchen A Game: Get-15 The game

More information

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 8 OO modeling Design Patterns Introduction Creational Patterns Software

More information

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Template Method Pattern. George Blankenship

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Template Method Pattern. George Blankenship CSCI 253 Object Oriented Design: George Blankenship George Blankenship 1 Creational Patterns Singleton Abstract factory Factory Method Prototype Builder Overview Structural Patterns Composite Façade Proxy

More information

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

EMBEDDED SYSTEMS PROGRAMMING Design Patterns EMBEDDED SYSTEMS PROGRAMMING 2015-16 Design Patterns DEFINITION Design pattern: solution to a recurring problem Describes the key elements of the problem and the solution in an abstract way Applicable

More information

Using Design Patterns in Java Application Development

Using Design Patterns in Java Application Development Using Design Patterns in Java Application Development ExxonMobil Research & Engineering Co. Clinton, New Jersey Michael P. Redlich (908) 730-3416 michael.p.redlich@exxonmobil.com About Myself Degree B.S.

More information

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D. Software Design Patterns Jonathan I. Maletic, Ph.D. Department of Computer Science Kent State University J. Maletic 1 Background 1 Search for recurring successful designs emergent designs from practice

More information

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson

Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson Lecture 2 and 3: Fundamental Object-Oriented Concepts Kenneth M. Anderson January 13, 2005 January 18, 2005 1 of 38 Lecture Goals Introduce the basic concepts of object-oriented analysis/design/programming

More information

DESIGN PATTERN - INTERVIEW QUESTIONS

DESIGN PATTERN - INTERVIEW QUESTIONS DESIGN PATTERN - INTERVIEW QUESTIONS http://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm Copyright tutorialspoint.com Dear readers, these Design Pattern Interview Questions

More information

Design Patterns and Frameworks Command

Design Patterns and Frameworks Command Design Patterns and Frameworks Command Oliver Haase Oliver Haase Emfra Command 1/13 Description Classification: Object-based behavioral pattern Purpose: Encapsulate a command as an object. Allows to dynamically

More information

Design Patterns. Vasileios Theodorou

Design Patterns. Vasileios Theodorou Design Patterns Vasileios Theodorou 1 A partitioning structural design pattern Motivation - Treat individual objects and compositions of objects uniformly Application - Objects are recursively composed

More information

Design Patterns (Part 2) CSCE Lecture 18-10/25/2016 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson)

Design Patterns (Part 2) CSCE Lecture 18-10/25/2016 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson) Design Patterns (Part 2) CSCE 740 - Lecture 18-10/25/2016 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson) Objectives for Today The point of OO: Separate what changes

More information

Ownership in Design Patterns. Master's Thesis Final Presentation Stefan Nägeli

Ownership in Design Patterns. Master's Thesis Final Presentation Stefan Nägeli Ownership in Design Patterns Master's Thesis Final Presentation Stefan Nägeli 07.02.06 Overview Status Quo Pattern Overview Encountered Problems applying UTS Pros and Cons compared to other systems UTS

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1 CSCI 6234 Object Oriented Design: Frameworks and Design Patterns George Blankenship Frameworks and Design George Blankenship 1 Background A class is a mechanisms for encapsulation, it embodies a certain

More information

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently. Gang of Four Software Design Patterns with examples STRUCTURAL 1) Adapter Convert the interface of a class into another interface clients expect. It lets the classes work together that couldn't otherwise

More information

Information systems modelling UML and service description languages

Information systems modelling UML and service description languages Internet Engineering Tomasz Babczyński, Zofia Kruczkiewicz Tomasz Kubik Information systems modelling UML and service description languages Overview of design patterns for supporting information systems

More information

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

EMBEDDED SYSTEMS PROGRAMMING Design Patterns EMBEDDED SYSTEMS PROGRAMMING 2014-15 Design Patterns DEFINITION Design pattern: solution to a recurring problem Describes the key elements of the problem and the solution in an abstract way Applicable

More information