Outline. Design Patterns, cont. Wrappers. Adapter Pattern. Based on material by Michael Ernst, University of Washington

Size: px
Start display at page:

Download "Outline. Design Patterns, cont. Wrappers. Adapter Pattern. Based on material by Michael Ernst, University of Washington"

Transcription

1 Outline Design Patterns, cont. Based on material by Michael Ernst, University of Washington Design patterns Creational patterns, recap Subtypes: Factory method, Factory object, Prototype Sharing: Singleton and Interning Structural patterns Adapter, Composite, Decorator, Proxy Behavioral patterns Interpreter, Procedural and Visitor Spring 8 CSCI 600, K. Kuzmin, A Milanova Wrappers Adapter Pattern A wrapper uses composition/delegation A wrapper is a thin layer over an encapsulated object Modify the interface Extend behavior Restrict access to encapsulated object The encapsulated object (delegate) does most work Adapter: modifies interface, same functionality Decorator: same interface, extends functionality Proxy: same interface, same functionality Spring 8 CSCI 600, K. Kuzmin, A Milanova (based on slide by Michael Ernst) 3 Line Motivation: reuse a class with an interface different that the class interface Shape BoundingBox() CreateManipulator() BoundingBox() CreateManipulator() Text Editor BoundingBox() CreateManipulator() text TextView GetExtent() return text.getextent(); return new TextManipulator; 4

2 Adapter Example: Scaling Rectangles interface Rectangle void scale(int factor); //grow or shrink by factor void setwidth(); float getwidth(); float area(); class Client void clientmethod(rectangle r) r.scale(); class NonScalableRectangle void setwidth(); // no scale method! Spring 8 CSCI 600, K. Kuzmin, A Milanova (example due to Michael Ernst) 5 Class Adapter Class adapter adapts via subclassing class ScalableRectangle extends NonScalableRectangle implements Rectangle void scale(int factor) setwidth(factor*getwidth()); setheight(factor*getheight()); Spring 8 CSCI 600, K. Kuzmin, A Milanova 6 Object Adapter Object adapter adapts via delegation: it forwards work to delegate class ScalableRectangle implements Rectangle NonScalableRectangle r; // delegate ScalableRectangle(NonScalableRectangle r) this.r = r; void scale(int factor) setwidth(factor * getwidth()); setheight(factor * getheight()); float getwidth() return r.getwidth(); Spring 8 CSCI 600, K. Kuzmin, A Milanova 7 Adapter Pattern The purpose of the Adapter is: change an interface, without changing the functionality of the encapsulated class Allows reuse of functionality Protects client from modification Reasons Rename methods Convert units Implement a method in terms of another Spring 8 CSCI 600, K. Kuzmin, A Milanova 8

3 Exercise A Point-of-Sale system needs to support various services provided by third-party vendors: Tax calculator service from some vendor Credit authorization service from some vendor Inventory systems from some vendor Accounting systems from some vendor We anticipate to change vendors Each vendor service has its own API, which can t be changed What design pattern helps address this problem? Spring 8 CSCI 600, K. Kuzmin, A Milanova 9 POS System The Solution: Object Adapter TaxMasterAdapter gettaxes(sale) : List of TaxLineItems <<interface>> IAccountingServiceAdapter postreceivable(creditpayment) postsale(sale) <<interface>> ITaxCalculatorAdapter gettaxes(sale) : List of TaxLineItems GoodAsGoldTaxProAdapter gettaxes(sale) : List of TaxLineItems <<interface>> ICreditAuthorizationServiceAdapter requestapproval(creditpayment, TerminalID, MerchantID) Exercise Who creates the appropriate adapter object? Is it a good idea to let some domain object from Point-of-Sale system (e.g., Register, Sale) create the adapters? That would assigns responsibility beyond the object s logic. We would like to keep domain classes focused, so, this is not a good idea How to determine what type of adapter object to create? We expect adapters to change What design patterns address this problem? The Solution: Factory ServiceFactory - accountingadapter : IAccountingAdapter - inventoryadapter : IInventoryAdapter - taxcalculatoradapter : ITaxCalculatorAdapter + getaccountingadapter() : IAccountingAdapter + getinventoryadapter () : IInventoryAdapter + gettaxcalculatoradapter () : ITaxCalculatorAdapter Spring 8 CSCI 600, K. Kuzmin, A Milanova 3

4 Using the Factory public ITaxCalculatorAdapter gettaxcalculatoradapter() if (taxcalculatoradapter == null) String classname = System.getProperty( taxcalculator.classname ); taxcalculatoradapter = (ITaxCalculatorAdapter) Class.forName(className).newInstance(); return taxcalculatoradapter; What design pattern(s) do you see here? Java reflection: creates a brand new object from String classname! 3 Exercise Who creates the ServiceFactory? How is it accessed? We need a single instance of the ServiceFactory What pattern addresses these problems? Spring 8 CSCI 600, K. Kuzmin, A Milanova 4 The Solution: Singleton Special UML notation. Outline - instance: ServiceFactory ServiceFactory - accountingadapter : IAccountingAdapter - inventoryadapter : IInventoryAdapter - taxcalculatoradapter : ITaxCalculatorAdapter + getinstance() : ServiceFactory + getaccountingadapter() : IAccountingAdapter + getinventoryadapter() : IInventoryAdapter + gettaxcalculatoradapter() : ITaxCalculatorAdapter In UML, - means private, + means public. All (shown) fields in ServiceFactory are private and all methods are public. underline means static. instance and getinstance are static. Single instance of ServiceFactory ensures single instance of adapter objects. Design patterns Creational patterns, recap Subtypes: Factory method, Factory object, Prototype Sharing: Singleton and Interning Structural patterns Adapter, Composite, Decorator, Proxy Behavioral patterns Interpreter, Procedural and Visitor Spring 8 CSCI 600, K. Kuzmin, A Milanova 6 4

5 Composite Pattern Good for part-whole relationships Can represent arbitrarily complex objects Client treats a composite object (a collection of objects) the same as a simple object (an atomic unit) Spring 8 CSCI 600, K. Kuzmin, A Milanova 7 Bicycle Example: Bicycle Wheel Skewer Hub Lever Body Cam Rod Acorn nut Spokes Frame Spring 8 CSCI 600, K. Kuzmin, A Milanova (due to Michael Ernst) 8 Example: Methods on Components abstract class BicycleComponent float cost(); Skewer is an atomic unit class Skewer extends BicycleComponent float price; float cost() return price; class Wheel extends BicycleComponent float assemblycost; Skewer skewer; Hub hub; float cost() return assemblycost+ Wheel is a collection of objects skewer.cost()+hub.cost()+ Spring 8 CSCI 600, K. Kuzmin, A Milanova (example due to Michael Ernst) 9 Even Better abstract class BicycleComponent float cost(); class Skewer extends BicycleComponent float price; float cost() return price; class Wheel extends BicycleComponent float assemblycost; BicycleComponent skewer; BicycleComponent hub; float cost() return assemblycost+ The skewer and hub are BicycleCompoenents, so we can use BicycleComponent! skewer.cost()+hub.cost()+ Spring 8 CSCI 600, K. Kuzmin, A Milanova 0 5

6 Another Example: Boolean Expressions A boolean expression can be Variable (e.g., x) Boolean constant: true, false Or expression (e.g., x or true) And expression (e.g., (x or true) and y) Not expression (e.g., not x, not (x or y)) And, Or, Not: collections of expressions Variable and Constant: atomic units Spring 8 CSCI 600, K. Kuzmin, A Milanova Using Composite to Represent Boolean Expressions abstract class BooleanExp abstract boolean eval(context c); class Constant extends BooleanExp private boolean const; Constant(boolean const) this.const=const; boolean eval(context c) return const; class extends BooleanExp String varname; (String var) this.varname = var; boolean eval(context c) return c.lookup(varname); Spring 8 CSCI 600, K. Kuzmin, A Milanova Using Composite to Represent Boolean Expressions class extends BooleanExp private BooleanExp leftexp; private BooleanExp rightexp; (BooleanExp left, BooleanExp right) leftexp = left; rightexp = right; boolean eval(context c) return leftexp.eval(c) && rightexp.eval(c); // analogous definitions for OrExp and NotExp Spring 8 CSCI 600, K. Kuzmin, A Milanova 3 Object Structure versus Class Diagram Expression (x or true) and y new ( new OrExp( new ( x ), new Constant(true) ), new ( y ) ) leftexp OrExp: x or true : (x or true) and y leftexp rightexp rightexp : y : x Constant: true Spring 8 CSCI 600, K. Kuzmin, A Milanova 4 6

7 Client Object Structure vs. Class Diagram BooleanExp Exercise: Object Structure Draw the object structure (a tree!) for expression x and true and (y or z) Constant NotExp OrExp Spring 8 CSCI 600, K. Kuzmin, A Milanova 5 Spring 8 CSCI 600, K. Kuzmin, A Milanova 6 Structure of Composite Another Option: Add Operations to Manage Composites Client Component operation() Client Component operation() add(component) remove(component) getchild(int) Leaf Composite Leaf Composite operation() operation() children operation() operation() add(component) remove(component) getchild(int) children 7 7

8 Wrapper Patterns A wrapper uses composition/delegation A wrapper is a thin layer over an encapsulated class Modify the interface Extend behavior Restrict access to encapsulated object The encapsulated object (delegate) does most work Adapter: modifies interface, same functionality Decorator: same interface, extends functionality Proxy: same interface, same functionality Spring 8 CSCI 600, K. Kuzmin, A Milanova (based on slide by Michael Ernst) 9 Decorator Pattern Another wrapper pattern Adapter is a wrapper, Composite is not Add functionality without changing the interface Problem, i.e., when to use: Add to existing method to do something in addition (while preserving the original specification and interface) Spring 8 CSCI 600, K. Kuzmin, A Milanova 30 Structure of Decorator Example Motivation: add small chunks of functionality without changing the interface ConcreteComponent Operation() ConcreteDecoratorA Operation() addedstate Component Operation() Decorator Operation() ConcreteDecoratorB Operation() AddedBehavior() component component->operation() component.operation() Decorator::Operation(); super.operation() AddedBehavior(); Spring 8 CSCI 600, K. Kuzmin, A Milanova 3 abstract class Component void draw(); class TextView extends Component public void draw() // Draw the TextView abstract class Decorator extends Component private Component component; public Decorator(Component c) this.component = c; public void draw() component.draw(); 3 8

9 Example Adds a border to the text view Example class BorderDecorator extends Decorator public BorderDecorator(Component c, int borderwidth) super(c); Calls Decorator.draw which redirects work to the enclosed component private void drawborder() public void draw() super.draw(); drawborder(); Adds a scroll bar to the text view class ScrollDecorator extends Decorator 33 public class Client public static void main(string[] args) TextView textview = new TextView(); Component decoratedcomponent = new BorderDecorator( new ScrollDecorator(textView),); decoratedcomponent.draw(); Spring 8 CSCI 600, K. Kuzmin, A Milanova 34 Java I/O Package InputStream: byte input streams Readers: character input streams InputStream Reader FileInputStream PipedInputStream FilterInputStream in StringReader PipedReader BufferdReader FilterReader in BufferedInputSteam #byte[] buf CheckedInputStream DataInputStream FilterInputStream is a Decorator. Enables the chaining of streams Each FilterInputStream redirects input action to the 35 enclosed InputStream PushbackReader FilterReader extends Reader Reader in; int read() return in.read(); Spring 8 CSCI 600, K. Kuzmin, A Milanova 36 9

10 Another Decorator Example public class UppercaseConvertor extends FilterReader public UppercaseConvertor(Reader in) super(in); public int read() throws IOException int c = super.read(); return ( c==-? c : Character.toUpperCase((char)c)); We also have LowercaseConverter extends FilterReader, which (surprise!) converts to lowercase 37 Another Decorator Example public static void main(string[] args) Reader f = new UppercaseConverter( new LowercaseConvertor( new StringReader(args[0]))); int c; while ((c = f.read())!= -) System.out.print((char)c); System.out.println(); What is the object structure of f? What does this code do? 38 Proxy Pattern Proxy Example: Manage Creation of Expensive Object Same interface and functionality as the enclosed class Control access to enclosed object Communication: manage network details when using a remote object Locking: serialize access by multiple clients Security: permit access only if proper credentials Creation: object might not yet exist (creation is expensive). Hide latency when creating object. Avoid work if object never used Spring 8 CSCI 600, K. Kuzmin, A Milanova (slide due to Michael Ernst) 39 Editor Image draw() getextent() store() load() ImageImp extent image Graphic draw() getextent() store() load() ImageProxy draw() getextent() store() load() filename extent if (image == null) // load image image.draw(); if (image == null) return extent; else return image.getextent(); 40 0

11 Proxy Example: Manage Details When Dealing with Remote Object Recovery from remote service failure in the Point-Of-Sale system When postsale is sent to an accounting service (remember, an AccountingAdapter), if connection cannot be established, failover to a local service Failover should be transparent to Register I.e., it should not know whether postsale was sent to the accounting service or to some special object that will redirect to a local service in case of failure Spring 8 CSCI 600, K. Kuzmin, A Milanova 4 Proxy Example: Manage Details When Dealing with Remote Object Register accounting:iaccountingadapter +makepayment() - compeletesalehandling() AccountingRedirectionProxy <<interface>> IAccountingAdapter + postsale( Sale ) - externalaccounting : IAccountingAdapter - localaccounting : IAccountingAdapter + postsale( Sale ) ExternalAccounting Adapter + postsale( Sale ) LocalAccounting Adapter + postsale( Sale ) Spring 8 CSCI 600, K. Kuzmin, A Milanova 4 Outline Design patterns Creational patterns, recap Subtypes: Factory method, Factory object, Prototype Sharing: Singleton and Interning Structural patterns Adapter, Composite, Decorator, Proxy Behavioral patterns for traversing composites Interpreter, Procedural and Visitor Spring 8 CSCI 600, K. Kuzmin, A Milanova 43 Traversing Composites Question: How to perform operations on composite objects (on all parts of the component)? E.g., evaluate a boolean expression, print a boolean expression The Interpeter, Procedural and Visitor patterns address this question Spring 8 CSCI 600, K. Kuzmin, A Milanova 44

12 Composite Objects Expression (x or true) and y new ( new OrExp( new ( x ), new Constant(true) ), new ( y ) ) leftexp We have a hierarchical structure: is top, OrExp and are below in the hierarchy, etc. OrExp: x or true : (x or true) and y leftexp rightexp rightexp : y Client Constant Composite Pattern: Class diagram BooleanExp NotExp OrExp : x Constant: true Spring 8 CSCI 600, K. Kuzmin, A Milanova 45 Atomic Units Composite Spring 8 CSCI 600, K. Kuzmin, A Milanova Objects 46 Perform Operations on boolean expressions Interpreter and Procedural Patterns Need to write code for each Operation/Object pair Objects Operations evaluate Constant OrExp NotExp Question: do we group together (in a class) the code for a particular operation or the code for a particular object Interpreter: groups code per object, spreads apart code for similar operations evaluate Procedural: groups code per operation, spreads apart code for similar objects evaluate prettyprint prettyprint prettyprint Spring 8 CSCI 600, K. Kuzmin, A Milanova 47 Spring 8 CSCI 600, K. Kuzmin, A Milanova (based on slide by Michael Ernst) 48

13 Interpeter Pattern evaluate prettyprint abstract class BooleanExp abstract boolean eval(context c); abstract String ; class extends BooleanExp boolean eval(context c); Add a method to each class String ; for each supported operation class extends BooleanExp boolean eval(context c); Dynamic dispatch chooses String ; right implementation at call myexpr.eval(c); Spring 8 CSCI 600, K. Kuzmin, A Milanova 49 Client Constant Interpreter Pattern BooleanExp boolean String NotExp OrExp Spring 8 CSCI 600, K. Kuzmin, A Milanova 50 Interpreter Pattern abstract class BooleanExp boolean eval(context c); class Constant extends BooleanExp private boolean const; Constant(boolean const) this.const=const; boolean eval(context c) class extends BooleanExp String varname; (String var) varname = var; boolean eval(context c) Spring 8 CSCI 600, K. Kuzmin, A Milanova 5 Interpreter Pattern class extends BooleanExp private BooleanExp leftexp; private BooleanExp rightexp; (BooleanExp left, BooleanExp right) leftexp = left; rightexp = right; boolean eval(context c) // analogous definitions for OrExp and NotExp Spring 8 CSCI 600, K. Kuzmin, A Milanova 5 3

14 Procedural pattern evaluate prettyprint // Classes for expressions don t have eval class Evaluate boolean evalconstexp(constant c) c.value(); // returns value of constant boolean eval( e) BooleanExp leftexp = e.leftexp; BooleanExp rightexp = e.rightexp; //Problem: How to invoke the right //implementation for leftexp and rightexp? Spring 8 CSCI 600, K. Kuzmin, A Milanova 53 Procedural pattern evaluate prettyprint // Classes for expressions don t have eval class Evaluate Context c; boolean evalexp(booleanexp e) if (e instanceof ) return eval(() e); else if (e instanceof Constant) return evalconstexp(() e); else if (e instanceof OrExp) return evalorexp((orexp)e); else What is the problem with this code? Spring 8 CSCI 600, K. Kuzmin, A Milanova 54 Visitor Pattern, a variant of the Procedural pattern Visitor helps traverse a hierarchical structure Nodes (objects in the hierarchy) accept visitors Visitors visit nodes (objects) class SomeBooleanExp extends BooleanExp void accept(visitor v) for each child of this node child.accept(v); n.accept(v) traverses the structure rooted at n, performing v s operation on every element class Visitor void visit(somebooleanexp e) do work on e Spring 8 CSCI 600, K. Kuzmin, A Milanova (based on slide by Michael Ernst) 55 Visitor Pattern class extends BooleanExp void accept(visitor v) class extends BooleanExp BooleanExp leftexp; BooleanExp rightexp; void accept(visitor v) leftexp.accept(v); rightexp.accept(v); class Evaluate implements Visitor void visit( e) //evaluate var exp void visit( e) //evaluate And exp class PrettyPrint implements Visitor Spring 8 CSCI 600, K. Kuzmin, A Milanova 56 4

15 The Interpreter Pattern BooleanExp Client String The Visitor Pattern BooleanExp Client accept(visitor v) Constant NotExp OrExp Constant accept (Visitor v) accept (Visitor v) NotExp accept (Visitor v) OrExp accept (Visitor v) accept (Visitor v) Spring 8 CSCI 600, K. Kuzmin, A Milanova The Visitor Pattern Visitor EvaluateVisitor visit(constant e) visit( e) visit(notexp e) visit( e) visit(orexp e) visit(constant e) visit( e) visit(notexp e) visit( e) visit(orexp e) PrettyPrintVisitor visit(constant e) visit( e) visit(notexp e) visit( e) visit(orexp e) Spring 8 CSCI 600, K. Kuzmin, A Milanova 59 Question class extends BooleanExp void accept(visitor v) class Constant extends BooleanExp void accept(visitor v) Why not move void accept(visitor v) up into superclass BooleanExp? class Evaluate implements Visitor void visit( e) void visit(constant e) void visit( e) 60 5

16 Exercise: Write Count Visitor which counts #subexpressions in a BooleanExp object class extends BooleanExp void accept(visitor v) class extends BooleanExp BooleanExp leftexp; BooleanExp rightexp; void accept(visitor v) leftexp.accept(v); rightexp.accept(v); class CounterVisitor implements Visitor int count = 0; void visit( e) void visit(constant e) void visit( e) 6 Starting the Visitor BooleanExp myexp = new ( new OrExp(new ( x ),new ( y )), new ( z ) ); Visitor v = new CounterVisitor(); myexp.accept(v); Spring 7 CSCI 600, A Milanova 6 Exercise: Write Evaluate Visitor which evaluates a BooleanExp object class extends BooleanExp void accept(visitor v) class extends BooleanExp BooleanExp leftexp; BooleanExp rightexp; void accept(visitor v) leftexp.accept(v); rightexp.accept(v); class EvaluateVisitor implements Visitor //?? void visit( e) //?? void visit(constant e) //?? void visit( e) //?? 63 Exercise: Write a Visitor that Computes the Cost of a Bicycle Component (Note: Cost of a composite is sum of costs of components + assembly cost) class Skewer extends BycicleComponent void accept(visitor v) class Wheel extends BycicleComponent BycicleComponent skewer; BycicleComponent hub; void accept(visitor v) skewer.accept(v); hub.accept(v); class CostVisitor implements Visitor void visit(skewer e) void visit(hub e) void visit(wheel e) 64 6

17 Visitor Pattern Must add definitions of visit (in Visitor hierarchy) and accept (in Object hierarchy) visit may do many different things: evaluate, count nodes, pretty print, etc. It is easy to add operations (a new Visitor class), hard to add nodes (must modify entire hierarchy of Visitors) Visitors are similar to iterators but different because they have knowledge of structure not just sequence Spring 8 CSCI 600, K. Kuzmin, A Milanova 65 Visitor Pattern s Double Dispatch evaluate prettyprint myexp.accept(v): we want to choose the right operation myexp.accept(v) // dynamically dispatch the right // implementation of accept, e.g.,.accept class void accept(visitor v) // at compile-time, chooses the // method family: visit(). At // runtime, dispatches the right implementation of // visit(), e.g., // EvaluateVisitor.visit() 66 Design Patterns Summary so Far Factory method, Factory class, Prototype Creational patterns: address problem that constructors can t return subtypes Singleton, Interning Creational patterns: address problem that constructors always return a new instance of class Wrappers: Adapter, Decorator, Proxy Structural patterns: when we want to change interface or functionality of an existing class, or restrict access to an object Spring 8 CSCI 600, K. Kuzmin, A Milanova 67 Design Patterns Summary so Far Composite A structural pattern: expresses whole-part structures, gives uniform interface to client Interpreter, Procedural, Visitor Behavioral patterns: address the problem of how to traverse composite structures Spring 8 CSCI 600, K. Kuzmin, A Milanova 68 7

Design patterns (part 2) CSE 331 Spring 2010

Design patterns (part 2) CSE 331 Spring 2010 Design patterns (part 2) CSE 331 Spring 2010 Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout) Behavioral patterns (affecting

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Design Patterns, Part 2 1 Outline ü Introduction to design patterns ü Creational patterns (constructing objects) Þ Structural patterns (controlling

More information

Design patterns (part 2)

Design patterns (part 2) Design patterns (part 2) CSE 331 University of Washington Michael Ernst Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout)

More information

Design patterns (part 3)

Design patterns (part 3) Design patterns (part 3) CSE 331 University of Washington Michael Ernst Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout)

More information

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3 Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3 Steve Chenoweth Phone: Office (812) 877-8974 Cell (937) 657-3885 Email: chenowet@rose-hulman.edu Gang of Four (GoF) http://www.research.ibm.com/designpatterns/pubs/ddj-eip-award.htm

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Design Patterns Part 3 (Slides by Mike Ernst and David Notkin) 1 Outline ü Introduction to design patterns ü Creational patterns (constructing

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Design Patterns, Part 2 (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Announcements Course

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2016 Design Patterns, Part 2 (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Announcements Course

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

Professor Barb Cutler and the rest of the Submitty team for the Homework Server!

Professor Barb Cutler and the rest of the Submitty team for the Homework Server! Review THANKS! Professor Barb Cutler and the rest of the Submitty team for the Homework Server! Mentors: Victor Zhu, Michael Zemski, Tyler Sontag, Max Wang, Joyce Yom, Ruoyu Chen TAs: Smit Pandit, Saswata

More information

Softwaretechnik. Design Patterns. Stephan Arlt SS University of Freiburg. Stephan Arlt (University of Freiburg) Softwaretechnik SS / 47

Softwaretechnik. Design Patterns. Stephan Arlt SS University of Freiburg. Stephan Arlt (University of Freiburg) Softwaretechnik SS / 47 Softwaretechnik Design Patterns Stephan Arlt University of Freiburg SS 2011 Stephan Arlt (University of Freiburg) Softwaretechnik SS 2011 1 / 47 Design Patterns Gamma, Helm, Johnson, Vlissides: Design

More information

Softwaretechnik. Design Patterns. Matthias Keil. Albert-Ludwigs-Universität Freiburg

Softwaretechnik. Design Patterns. Matthias Keil. Albert-Ludwigs-Universität Freiburg Softwaretechnik Design Patterns Matthias Keil Institute for Computer Science Faculty of Engineering University of Freiburg 14. Juni 2012 Design Patterns (1) solutions for specific problems in object-oriented

More information

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Outline Subtype polymorphism Subtyping vs. subclassing Liskov Substitution Principle (LSP) Function subtyping Java subtyping Composition:

More information

Decorator Pattern. CS356 Object-Oriented Design and Programming November 7, 2014

Decorator Pattern. CS356 Object-Oriented Design and Programming   November 7, 2014 Decorator Pattern CS356 Object-Oriented Design and Programming http://cs356.yusun.io November 7, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Decorator Intent Dynamically attach additional responsibilities

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

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

Design Patterns So Far. Design Patterns, cont. Design Patterns So Far. Outline

Design Patterns So Far. Design Patterns, cont. Design Patterns So Far. Outline Design Patterns So Far Design Patterns, cont. Creational patterns: Factories, Prototype, Singleton, Interning Problem: constructors (in Java and other OO languages) are inflexible 1. Can t return a subtype

More information

The Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

The Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits) The Java I/O System Binary I/O streams (ASCII, 8 bits) InputStream OutputStream The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing binary I/O to character I/O

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

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

The Decorator Pattern. Design Patterns In Java Bob Tarr

The Decorator Pattern. Design Patterns In Java Bob Tarr The Decorator Pattern Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Also Known As Wrapper Motivation

More information

Design Patterns. Decorator. Oliver Haase

Design Patterns. Decorator. Oliver Haase Design Patterns Decorator Oliver Haase 1 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,

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

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

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

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

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

BFH/HTA Biel/DUE/Course 355/ Software Engineering 2

BFH/HTA Biel/DUE/Course 355/ Software Engineering 2 Visitor [GoF] Intent Parameterize behavior of elements of an object structure. Motivation Hard-coding the behavior of an object structure such as an abstract syntax tree requires re-writing the nodes classes.

More information

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns Today we are going to talk about an important aspect of design that is reusability of design. How much our old design

More information

Design Pattern and Software Architecture: IV. Design Pattern

Design Pattern and Software Architecture: IV. Design Pattern Design Pattern and Software Architecture: IV. Design Pattern AG Softwaretechnik Raum E 3.165 Tele.. 60-3321 hg@upb.de IV. Design Pattern IV.1 Introduction IV.2 Example: WYSIWYG Editor Lexi IV.3 Creational

More information

BFH/HTA Biel/DUE/Course 355/ Software Engineering 2

BFH/HTA Biel/DUE/Course 355/ Software Engineering 2 Interpreter [GoF] Intent Given a language, define a representation of its grammar along with an interpreter that uses the representation to interpret sentences in the language. Motivation Many problems

More information

Announcements. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Intuition: Type Signature is a Specification.

Announcements. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Intuition: Type Signature is a Specification. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle Announcements HW5 is due today, March 26, 2018 at 11:59:59 pm Exam 2 is next Thursday, March 29, 2018. Practice exam has been

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

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4 Subtype, Subtyping vs. Subclassing, Liskov Substitution Principle Announcements n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Outline of today s class. Design Patterns. Classes and Inheritance. Aside: UML Class Diagrams

Outline of today s class. Design Patterns. Classes and Inheritance. Aside: UML Class Diagrams Outline of today s class Unified Modeling Language (UML) Design Patterns Based on material by Michael Ernst, University of Washington Design patterns Intro to design patterns Creational patterns Factories:

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

Aggregation. Chapter 8. Java By Abstraction Chapter 8. Outline. 8.1 What is Aggregation? Copyright 2006 Pearson Education Canada Inc.

Aggregation. Chapter 8. Java By Abstraction Chapter 8. Outline. 8.1 What is Aggregation? Copyright 2006 Pearson Education Canada Inc. Chapter 8 Aggregation Java By Abstraction 8- Outline 8. What is Aggregation? 8.. Definition and Terminology 8..2 The Aggregate s Constructor 8..3 Accessors and Mutators 8..4 The Client s Perspective 8..5

More information

Composite Pattern - Shapes Example - Java Sourcecode

Composite Pattern - Shapes Example - Java Sourcecode Composite Pattern - Shapes Example - Java Sourcecode In graphics editors a shape can be basic or complex. An example of a simple shape is a line, where a complex shape is a rectangle which is made of four

More information

CS 520/620 Advanced Software Engineering Spring February 02, 2016

CS 520/620 Advanced Software Engineering Spring February 02, 2016 CS 520/620 Advanced Software Engineering Spring 2016 February 02, 2016 Logistics Project proposals Elevator pitches on Thursday Deadline for creating groups: 02/03/2016, 11:55pm Deadline for submitting

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

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya ADAPTER Presented By: Mallampati Bhava Chaitanya Topics Intent Motivation Applicability Structure Participants & Collaborations Consequences Sample Code Known Uses Related Patterns Intent Convert the interface

More information

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

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

What is a Pattern? Lecture 40: Design Patterns. Elements of Design Patterns. What are design patterns?

What is a Pattern? Lecture 40: Design Patterns. Elements of Design Patterns. What are design patterns? What is a Pattern? Lecture 40: Design Patterns CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki "Each pattern describes a problem which occurs over and over again in our environment, and then describes

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

Section 9: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst

Section 9: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst What Is A Design Pattern A standard solution to a common programming problem A technique for

More information

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2 CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,

More information

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

Chapter 8, Design Patterns Visitor

Chapter 8, Design Patterns Visitor Chapter 8, Design Patterns Visitor Using UML, Patterns, and Java Object-Oriented Software Engineering Pattern A Pattern Taxonomy Structural Pattern Behavioral Pattern Creational Pattern Composite Decorator

More information

An Introduction to Patterns

An Introduction to Patterns An Introduction to Patterns Robert B. France Colorado State University Robert B. France 1 What is a Pattern? - 1 Work on software development patterns stemmed from work on patterns from building architecture

More information

Design Patterns. Decorator Pattern. Ekim 2017

Design Patterns. Decorator Pattern. Ekim 2017 Design Patterns Decorator Pattern ebru@hacettepe.edu.tr ebruakcapinarsezer@gmail.com http://yunus.hacettepe.edu.tr/~ebru/ @ebru176 Ekim 2017 Let s try to design Each football player has the abilities of

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

Object-Oriented Oriented Programming Adapter Pattern. CSIE Department, NTUT Woei-Kae Chen

Object-Oriented Oriented Programming Adapter Pattern. CSIE Department, NTUT Woei-Kae Chen Object-Oriented Oriented Programming Adapter Pattern CSIE Department, NTUT Woei-Kae Chen Adapter: Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work

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

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7) Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual

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

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

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

6.170 Lecture 15 Design Patterns

6.170 Lecture 15 Design Patterns Outline 6.170 Lecture 15 Design Patterns Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout) Behavioral patterns (affecting object semantics)

More information

Section 8: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst

Section 8: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst Section 8: Design Patterns Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst Announcements HW8 due tonight 10 pm Quiz 7 due tonight 10 pm Industry guest speaker tomorrow!

More information

Learning the Java Language. 2.1 Object-Oriented Programming

Learning the Java Language. 2.1 Object-Oriented Programming Learning the Java Language 2.1 Object-Oriented Programming What is an Object? Real world is composed by different kind of objects: buildings, men, women, dogs, cars, etc. Each object has its own states

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

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

Review of last class. 1.Class inheritance versus interface inheritance 2.Inheritance versus composition. Dr. Xiaolin Hu

Review of last class. 1.Class inheritance versus interface inheritance 2.Inheritance versus composition. Dr. Xiaolin Hu Review of last class 1.Class inheritance versus interface inheritance 2.Inheritance versus composition Design patterns Creational Structural Behavioral Abstract Factory Builder Prototype Singleton etc.

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

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

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question) CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers

More information

CS 320 Introduction to Software Engineering Spring March

CS 320 Introduction to Software Engineering Spring March CS 320 Introduction to Software Engineering Spring 2017 March 20 2017 Today Logistics: timeline and assignments Overview of the study guide (midterm exam) Overview of the SDD requirements Recap of software

More information

An Introduction to Object Orientation

An Introduction to Object Orientation An Introduction to Object Orientation Rushikesh K Joshi Indian Institute of Technology Bombay rkj@cse.iitb.ac.in A talk given at Islampur Abstractions in Programming Control Abstractions Functions, function

More information

Software Engineering Design & Construction

Software Engineering Design & Construction Winter Semester 16/17 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Decorator Pattern Intent of the Decorator Pattern We need

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

CSE wi Final Exam 3/12/18. Name UW ID#

CSE wi Final Exam 3/12/18. Name UW ID# Name UW ID# There are 13 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

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

Top Down Design vs. Modularization

Top Down Design vs. Modularization 6.170 Quiz Review Topics: 1. Decoupling 2. 3. AF & RI 4. Iteration Abstraction & Iterators 5. OMs and Invariants 6. Equality, Copying, Views 7. 8. Design Patterns 9. Subtyping 10. Case Studies Decomposition

More information

CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking. Washington University Spring 2013 CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

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: State, Bridge, Visitor

Design Patterns: State, Bridge, Visitor Design Patterns: State, Bridge, Visitor State We ve been talking about bad uses of case statements in programs. What is one example? Another way in which case statements are sometimes used is to implement

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EINDHOVEN UNIVERSITY OF TECHNOLOGY EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics & Computer Science Exam Programming Methods, 2IP15, Wednesday 17 April 2013, 09:00 12:00 TU/e THIS IS THE EXAMINER S COPY WITH (POSSIBLY INCOMPLETE)

More information

Software 1 with Java. Recitation No. 7 (Java IO) May 29,

Software 1 with Java. Recitation No. 7 (Java IO) May 29, Software 1 with Java Recitation No. 7 (Java IO) May 29, 2007 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes

More information

Software Quality Management

Software Quality Management 2004-2005 Marco Scotto (Marco.Scotto@unibz.it) Outline Structural Patterns Adapter Composite Decorator 2 Design Pattern Space Purpose Creational Structural Behavioral Scope Class Factory Method Adapter

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

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

Object-Oriented Oriented Programming Adapter Pattern

Object-Oriented Oriented Programming Adapter Pattern Object-Oriented Oriented Programming Pattern CSIE Department, NTUT Woei-Kae Chen : Intent Convert the interface of a class into another interface clients expect. lets classes work together that could not

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative

More information

Decorator Pattern. Steven R. Bagley

Decorator Pattern. Steven R. Bagley Decorator Pattern Steven R. Bagley Introduction Decorator Pattern Inheritance vs. Composition Tricolour Coffee Bar Fast-growing coffee chain Started by a computer scientist Wants a fully OO based ordering

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

Section 9: Design Patterns. Slides adapted from Alex Mariakakis, with material from David Mailhot, Hal Perkins, Mike Ernst

Section 9: Design Patterns. Slides adapted from Alex Mariakakis, with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns Slides adapted from Alex Mariakakis, with material from David Mailhot, Hal Perkins, Mike Ernst Agenda What are design patterns? Creational patterns review Structural patterns

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 24 October 29, 2018 Arrays, Java ASM Chapter 21 and 22 Announcements HW6: Java Programming (Pennstagram) Due TOMORROW at 11:59pm Reminder: please complete

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

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

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng Design Patterns Acknowledgements Materials based on a number of sources D. Levine and D. Schmidt. Helm Gamma et al S. Konrad Motivation Developing software is hard Designing reusable software is more challenging

More information

TDDB84 Design Patterns Lecture 05. Builder, Singleton, Proxy. pelab

TDDB84 Design Patterns Lecture 05. Builder, Singleton, Proxy. pelab Lecture 05 Builder, Singleton, Proxy Peter Bunus Dept of Computer and Information Science Linköping University, Sweden petbu@ida.liu.se The Constitution of Software Architects Encapsulate what varies.

More information

Design Patterns. Claus Jensen

Design Patterns. Claus Jensen Design Patterns Claus Jensen What is a Design Pattern? A design pattern Abstracts a recurring design structure Distils design experience Promotes reuse of design and code Gives an opportunity to see how

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

More information