TDDB84 Design Patterns Lecture 02. Factory Method, Decorator

Size: px
Start display at page:

Download "TDDB84 Design Patterns Lecture 02. Factory Method, Decorator"

Transcription

1 Lecture 02 Factory Method, Decorator Peter Bunus Dept of Computer and Information Science Linköping University, Sweden Factory Method Pattern Peter Bunus 2 1

2 Time for Lunch Joe, with the money earned from the duck simulator I bought a Pizza shop. I want to improve a little bit the service here. I m thinking that it would be great if one could order a pizza over the Internet No problem boss. I can fix this. I m calling you back when I m ready. Peter Bunus 3 Ordering Pizza Pizza* orderpizza(){ cout << "Ordering pizza" << endl; Pizza *pizza = new Pizza(); pizza->prepare(); pizza->bake(); pizza->cut(); pizza->box(); return pizza; But we need more than one type of pizza OO inheritance can help us here Peter Bunus 4 2

3 Ordering Pizza Pizza* orderpizza(string type){ cout << "Ordering pizza" << endl; Pizza *pizza; if (type=="cheese"){ pizza = new CheesePizza; else if (type=="greek"){ pizza = new GreekPizza; else if (type=="pepperoni"){ pizza = new PepperoniPizza; pizza->prepare(); pizza->bake(); pizza->cut(); pizza->box(); return pizza; Peter Bunus 5 Joe, We cannot sell Greek pizza anymore. It is extremely hard to find goat cheese for this pizza. We need to have clam and veggie pizza instead Typical, I need to change the code one more time Peter Bunus 6 3

4 Pizza* orderpizza(string type){ cout << "Ordering pizza" << endl; Pizza *pizza; if (type=="cheese"){ pizza = new CheesePizza; else if (type=="greek"){ pizza = new GreekPizza; else if (type=="pepperoni"){ pizza = new PepperoniPizza; else if (type== clam ){ pizza = new ClamPizza; else if (type== veggie ){ pizza = new VeggiePizza; pizza->prepare(); pizza->bake(); pizza->cut(); pizza->box(); return pizza; Peter Bunus 7 The Constitution of Software Architectcts Encapsulate that vary. Program to an interface not to an implementation. Favor Composition over Inheritance. Peter Bunus 8 4

5 Encapsulate that vary Pizza* orderpizza(string type){ cout << "Ordering pizza" << endl; Pizza *pizza; if (type=="cheese"){ pizza = new CheesePizza; else if (type=="greek"){ pizza = new GreekPizza; else if (type=="pepperoni"){ pizza = new PepperoniPizza; else if (type== clam ){ pizza = new ClamPizza; else if (type== veggie ){ pizza = new VeggiePizza; pizza->prepare(); pizza->bake(); pizza->cut(); pizza->box(); return pizza; Encapsulate that vary!!! We should place this code in an object that is only going to worry about how to create pizzas. If any other object need a pizza created this is the object to come to Peter Bunus 9 Pizza Factory Pizza* PizzaFactory::createPizza(string type){ Pizza *pizza; if (type=="cheese"){ pizza = new CheesePizza; else if (type=="pepperoni"){ pizza = new PepperoniPizza; else if (type=="clam"){ pizza = new ClamPizza; else if (type=="veggie"){ pizza = new VeggiePizza; return pizza; orderpizza() orderpizza() orderpizza() PizzaShop Supermarket PizzaDelivery Peter Bunus 10 5

6 Pizza Shop class PizzaStore{ PizzaFactory *factory; public: PizzaStore(PizzaFactory *factory){ factory = p_factory; ; Pizza* orderpizza(string type){ Pizza *pizza; pizza = factory->createpizza(type); return pizza; ; ; orderpizza() int main(){ PizzaFactory *pizzafactory = new PizzaFactory(); PizzaStore *pizzastore = new PizzaStore(pizzaFactory); Pizza *mypizza = pizzastore->orderpizza("pepperoni"); return 0; Peter Bunus 11 Pizza Shop and Factory This is the client of the Factory. PizzaStore goes through the PizzaFactory to get instances of Pizza This is the the factory where we create pizzas; it should be only part of our aplication that refers to concrete Pizza classes This is the product of the factory pizza. We ve defined Pizza as an abstract class with some helpful implementation that can be overriden These are our concrete products. Each product needs to implement the Pizza interface (which means extend the abstract Pizza class) and be concrete. Peter Bunus 12 6

7 Pizza Shop and Factory Do we have a pattern here? NOT YET!!!! Peter Bunus 13 Pizza everywhere Joe, the Pizza store idea is really great. We are making a lot of money. I m out of the duck business. I would like to have pizza shops everywhere: Paris, Rome, Stockholm.. Una pepperoni pizza semplice, ma saporita con il delicato prosciutto, per favore. Je voudrais commander une pizza s'il vous plaît avec boeuf haché et sauce tomate. Je n'aime pas le bacon et le ananas. Jag skulle vilja ha en pepperoni pizza med kötbullar Peter Bunus 14 7

8 Regional Pizza Factories int main(){ ParisPizzaFactory *parispizzafactory = new ParisPizzaFactory(); PizzaStore *parispizzastore = new PizzaStore(parisPizzaFactory); Pizza *mypizza = parispizzastore->orderpizza("pepperoni"); return 0; int main(){ RomePizzaFactory *romepizzafactory = new RomePizzaFactory(); PizzaStore *romepizzastore = new PizzaStore(romePizzaFactory); Pizza *mypizza = romepizzastore->orderpizza("pepperoni"); return 0; Peter Bunus 15 class PizzaStore{ PizzaFactory *factory; public: PizzaStore(PizzaFactory *factory){ factory = p_factory; ; Pizza* orderpizza(string type){ Pizza *pizza; pizza = factory->createpizza(type); createpizza(type); return pizza; ; virtual createpizza(type); ; Pizza* PizzaFactory::createPizza(string type){ Pizza *pizza; if (type=="cheese"){ pizza = new CheesePizza; else if (type=="pepperoni"){ pizza = new PepperoniPizza; else if (type=="clam"){ pizza = new ClamPizza; else if (type=="veggie"){ pizza = new VeggiePizza; return pizza; Now we ve got a store waiting for subclasse Peter Bunus 16 8

9 RomePizzaStore +createpizza() virtual +createpizza() createpizza(type); +orderpizza() PizzaStore ParisPizzaStore +createpizza() createpizza() is abstract, so all pizza store subtypes MUST implement the method Pizza* RomePizzaStore::createPizza(string type){ if (type=="cheese"){ pizza = new RomeCheesePizza; else if (type=="pepperoni"){ pizza = new RomePepperoniPizza; else if (type=="clam"){ pizza = new RomeClamPizza; else if (type=="veggie"){ pizza = new RomeVeggiePizza; return pizza; StockholmPizzaStore Pizza* ParisPizzaStore::createPizza(string type){ if (type=="cheese"){ +createpizza() pizza = new ParisCheesePizza; else if (type=="pepperoni"){ pizza = new ParisPepperoniPizza; else if (type=="clam"){ pizza = new ParisClamPizza; else if (type=="veggie"){ pizza = new ParisVeggiePizza; return pizza; Peter Bunus 17 Do we have a pattern here? PizzaStore +createpizza() +orderpizza() RomePizzaStore ParisPizzaStore StockholmPizzaStore +createpizza() +createpizza() +createpizza() Pizza +prepare() +bake() +cut() +box() RomeCheesePizza RomePepperoniPizza RomeClamPizza RomeVeggiePizza... Peter Bunus 18 9

10 The Factory Method Pattern Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Peter Bunus 19 The Factory Method Pattern The Creator is a class that contains the implementation for all of the methods to manipulate products except for the factory method All products must implement the same interface so that the classes which use the products can refer to the interface not to the concrete class The abstract FactoryMethod() is what all Creator subclasses must implement. The ConcreteCreator is responsible for creating one or more concrete products. It is the only class that has the knowledge of how to create these products The ConcreteCreator implements the Factory Method() which is the method that actually produce products. Peter Bunus 20 10

11 The Factory Method Advantages/Disadvantages Eliminates the need to bind application-specific classes into your code Provides hooks for subclassing. Creating objects inside a class with a factory method is always more flexible than creating an object directly. This method gives subclasses a hook for providing an extended version of an object Connects parallel heirarchies. Factory method localises knowledge of which classes belong together. Parallel class heirarchies result when a class delegates some of its responsibilities to a separate class. Clients might have to subclass the Creator class just to create a particular Concreate object. Peter Bunus 21 class PizzaStore{ public: Pizza* orderpizza(string type){ Pizza *pizza; pizza = createpizza(type); return pizza; ; protected virtual createpizza(type); ; Provides hooks for subclassing. Creating objects inside a class with a factory method is always more flexible than creating an object directly. This method gives subclasses a hook for providing an extended version of an object. Peter Bunus 22 11

12 Connecting Parallel Class hierarchies Pizza +prepare() +bake() +cut() +box() RomeCheesePizza ParisCheesePizza SthmCheesePizza RomePepperoniPizza ParisPepperoniPizza SthmPepperoniPizza RomeClamPizza ParisClamPizza SthmClamPizza RomeVeggiePizza ParisVeggiePizza SthmVeggiePizza Connects parallel heirarchies. Factory method localises knowledge of which classes belong together. Parallel class heirarchies result when a class delegates some of its responsibilities to a separate class. Peter Bunus 23 Descriptive names class Complex{ public: static Complex fromcartesian(double real,double imag) { return new Complex(real, imag); static Complex frompolar(double rho, double theta) { return new Complex(rho * cos(theta), rho * sin(theta)); private: Complex(double a, double b) { //... ; In many object-oriented languages, constructors must have the same name as the class they are in, which can lead to ambiguity if there is more than one way to create an object. Factory methods have no such constraint and can have descriptive names. As an example, when complex numbers are created from two real numbers the real numbers can be interpreted as cartesian or polar coordinates, but using factory methods, the meaning is clear Complex c = Complex.fromPolar(1, pi); Peter Bunus 24 12

13 Factory Method Non Software Example Peter Bunus 25 Decorator Pattern Peter Bunus 26 13

14 Extending the Business Joe, people are not coming to our pizza places in the morning. They need coffee in the morning. I decided to open a coffee shop next to each pizzeria. Could you please implement an application for ordering coffee? Peter Bunus 27 The First Design of the Coffee Shop No problem boss. I can fix this. I have now experience with the pizza store so this will be a piece of cake The cost() method is abstract; subclasses need to define their implementation Each subclass implements cost() the cost of the beverage Peter Bunus 28 14

15 Class Explosion Beverage -description +getdescription() What I m doing wrong here? Which of the design principles we are violating here? HouseBlend DarkRoast Decaf Expresso Peter Bunus 29 The Constitution of Software Architectcts Encapsulate that vary. Program to an interface not to an implementation. Favor Composition over Inheritance. Peter Bunus 30 15

16 Why do we need so many classes??? We add instance variables to represent whether or not each beverage has milk, soy, mocha and whip... Now we ll implement cost() in Beverage (instead of keeping it abstract), so that it can calculate the costs associated with the condiments for a particular beverage instance. Subclasses will still override cost(), but they will also invoke the super version so that they can calculate the total cost of the basic beverage plus the costs of the added condiments. Peter Bunus 31 Excellent Joe, good job. Five classes. This will decrease the complexity of our ordering system I m not so sure about this. My experience with high management is not so good. They change the requirements all the time. An the customers they want new things all the time Peter Bunus 32 16

17 What can happend? New condiments will appear and will force us to add new methods and change the cost method each time Price changes for condiments so we need to change the cost method. New beverages like iced tea. The iced tee class will still inherit the methods like haswhip(). How about double espresso. Peter Bunus 33 Decorating Coffee Inheritance doesn t worked very well for us. What we should do? Hi Jamie. One of my guys have problem with coffee classes. Could you please help him out. 1. Take the DarkRoast object 2. Decorate it with a Mocha object 3. Decorate it with the Whip object 4. Call the cost() method and relay on delegation to add to the condiment cost. Peter Bunus 34 17

18 Jamie s recipe 1. Take the DarkRoast object cost() Whip cost() Mocha cost() DarkRoast 2. Decorate it with a Mocha object 3. Decorate it with the Whip object 4. Call the cost() method class DarkRoast : public Beverage{ public: DarkRoast(); double cost(); ; class Whip : public CondimentDecorator{ Beverage *beverage; public: Whip(Beverage *p_beverage) ; string getdescription(); double cost(); ; class Mocha : public CondimentDecorator{ Beverage *beverage; public: Mocha(Beverage *p_beverage) ; string getdescription(); double cost(); ; Peter Bunus 35 Barista Training for Sofware Engineers Beverage acts like an abstract component class HouseBlend Decaf Beverage -description +getdescription() class DarkRoast : public Beverage{ public: DarkRoast(); double cost(); ; Expresso DarkRoast * class Beverage{ public: string description; Beverage(); virtual string getdescription(); virtual double cost()=0; ; CondimentDecorator class CondimentDecorator 1 : public Beverage{ +getdescription()() public: CondimentDecorator(){; virtual string getdescription()=0; ; Milk Soy -beverage : Beverage -beverage : Beverage +getdescription() +getdescription() class Mocha : public CondimentDecorator{ Whip Mocha Beverage *beverage; -beverage : Beverage -beverage : Beverage public: Mocha(Beverage *p_beverage){ +getdescription() +getdescription() beverage = p_beverage; ; string getdescription(){ return beverage->getdescription()+ " Whip"; ; double cost(){ return beverage->cost() ; ; Peter ; Bunus 36 18

19 Running the Coffe Shop A Whipped Dark Roast with double Mocha expresso House blend void main(){ cout << "Testing the Coffe Shop application" << endl; Beverage *beverage1 = new Expresso(); cout << beverage1->getdescription() << endl; cout << "Cost: " << beverage1->cost() << endl << endl; Beverage *beverage2 = new DarkRoast(); beverage2 = new Mocha(beverage2); beverage2 = new Mocha(beverage2); beverage2 = new Whip(beverage2); cout << beverage2->getdescription() << endl; cout << "Cost: " << beverage2->cost() << endl << endl; Beverage *beverage3 = new HouseBlend(); cout << beverage3->getdescription() << endl; cout << "Cost: " << beverage3->cost() << endl << endl; Peter Bunus 37 Running the Coffe Shop void main(){ cout << "Testing the Coffe Shop application" << endl; Beverage *beverage1 = new Expresso(); cout << beverage1->getdescription() << endl; cout << "Cost: " << beverage1->cost() << endl << endl; Beverage *beverage2 = new DarkRoast(); beverage2 = new Mocha(beverage2); beverage2 = new Mocha(beverage2); beverage2 = new Whip(beverage2); cout << beverage2->getdescription() << endl; cout << "Cost: " << beverage2->cost() << endl << endl; Beverage *beverage3 = new HouseBlend(); cout << beverage3->getdescription() << endl; cout << "Cost: " << beverage3->cost() << endl << endl; Peter Bunus 38 19

20 How is the Cost Computed?... Beverage *beverage2 = new DarkRoast(); beverage2 = new Mocha(beverage2); beverage2 = new Mocha(beverage2); beverage2 = new Whip(beverage2); cout << beverage2->getdescription() << endl; cout << "Cost: " << beverage2->cost() << endl;... cost() Whip cost() Mocha cost() Mocha cost() DarkRoast double Whip::cost(){ return beverage->cost() ; = 3.55 double Mocha::cost(){ return beverage->cost() + 0.9; double DarkRoast::cost(){ return 0.99; Peter Bunus 39 The Decorator Pattern Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality Peter Bunus 40 20

21 The Constitution of Software Architectcts Encapsulate that vary. Program to an interface not to an implementation. Favor Composition over Inheritance. Classes should be open for extension but closed for modification Peter Bunus 41 Decorating Text Peter Bunus 42 21

22 Decorator Non Software Example Peter Bunus 43 The Decorator Advantages/Disadvantages Provides a more flexible way to add responsibilities to a class than by using inheritance, since it can add these responsibilities to selected instances of the class Allows to customize a class without creating subclasses high in the inheritance hierarchy. A Decorator and its enclosed component are not identical. Thus, tests for object types will fail. Decorators can lead to a system with lots of little objects that all look alike to the programmer trying to maintain the code Peter Bunus 44 22

23 What we have learned? Inheritance is one form of extension, but not necessarily he best way to achieve flexibility in our design In our design we should allow behavior to extended without the need to modify the existing code Composition and delegation can often be used to add new behaviors at runtime The Decorator Pattern involves a set of decorator classes that are used to wrap concrete components Decorators change the behavior of their components by adding new functionality before and/or after (or even in place of) method calls to the component Decorators can result in many small objects in our design, and overuse can be complex Peter Bunus 45 23

If we aren t supposed to program to an implementation then how can we actually create new things? Reptile reptile = new Turtle(); Software Engineering

If we aren t supposed to program to an implementation then how can we actually create new things? Reptile reptile = new Turtle(); Software Engineering CSC40232: SOFTWARE ENGINEERING Professor: Jane Cleland Huang Lecture 3: Observer Pattern Wednesday, January 18 th sarec.nd.edu/courses/se2017 Department of Computer Science and Engineering If we aren t

More information

03. DECORATOR PATTERN. Design Eye for the Inheritance Guy

03. DECORATOR PATTERN. Design Eye for the Inheritance Guy BIM492 DESIGN PATTERNS 03. DECORATOR PATTERN Design Eye for the Inheritance Guy Welcome to Starbuzz Coffee Starbuzz Coffee is the fastest growing coffee shop around --> if you see one, look across the

More information

TDDB84. Lecture 2. fredag 6 september 13

TDDB84. Lecture 2. fredag 6 september 13 TDDB84 Lecture 2 Yes, you can bring the books to the exam Creational Factory method Structural Decorator Behavioral LE2 Creational Abstract Factory Singleton Builder Structural Composite Proxy Bridge Adapter

More information

Interface. Design Patterns 2. Why use Interface? Design Principles. Adapter 11/7/2011. Michael Li

Interface. Design Patterns 2. Why use Interface? Design Principles. Adapter 11/7/2011. Michael Li G5APR Applications Programming Design Patterns Michael Li email: jwl@cs.nott.ac.uk http://www.cs.nott.ac.uk/~jwl/g5apr Interface An Interface is a collection of abstract methods that an object implements

More information

Laboratorio di Tecnologie dell'informazione. Ing. Marco Bertini

Laboratorio di Tecnologie dell'informazione. Ing. Marco Bertini Laboratorio di Tecnologie dell'informazione Ing. Marco Bertini bertini@dsi.unifi.it http://www.dsi.unifi.it/~bertini/ Design pattern Factory Some motivations Consider a user interface toolkit to support

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

g Baking with OO Goodness

g Baking with OO Goodness 4 the Factory Pattern h g Baking with OO Goodness g Get ready to bake some loosely coupled OO designs. There is more to making objects than just using the new operator. You ll learn that instantiation

More information

Factories, Builders and Singletons. Steven R. Bagley

Factories, Builders and Singletons. Steven R. Bagley Factories, Builders and Singletons Steven R. Bagley The Patterns So Far Behavioural Patterns Strategy Observer Structural Patterns Decorator Introduction Object Creational Patterns Sometimes new isn t

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

Decorating Objects. 3 the DecoratorPattern. Just call this chapter Design Eye for the Inheritance Guy.

Decorating Objects. 3 the DecoratorPattern. Just call this chapter Design Eye for the Inheritance Guy. 3 the DecoratorPattern g h Decorating Objects g I used to think real men subclassed everything. That was until I learned the power of extension at runtime, rather than at compile time. Now look at me!

More information

Applying the Factory Method Design Pattern

Applying the Factory Method Design Pattern Applying the Factory Method Design Pattern Trenton Computer Festival Professional Seminars Michael P. Redlich (908) 730-3416 michael.p.redlich@exxonmobil.com About Myself Degree B.S. in Computer Science

More information

Hands- On Design Patterns A 2- Day Crash Course

Hands- On Design Patterns A 2- Day Crash Course Hands- On Design Patterns A 2- Day Crash Course Nuno Flores - FEUP Software Engineering Group 1 Setup time Registering and signing in Grouping? Environment? Notebooks? All set? 2 1 Goals Before... + =

More information

Decorator. The Decorator pattern gives a mechanism without using inheritance.

Decorator. The Decorator pattern gives a mechanism without using inheritance. Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern gives a mechanism without using inheritance. The Decorator pattern allows one to add and

More information

Software Frameworks. Patterns and frameworks. Patterns and frameworks. Patterns and frameworks. Patterns and frameworks

Software Frameworks. Patterns and frameworks. Patterns and frameworks. Patterns and frameworks. Patterns and frameworks Software Frameworks Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 More design patterns They are code libraries designed to facilitate software development. Examples: Ruby on Rails:

More information

Design Patterns. CSCE Lecture 17-10/28/2015 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson)

Design Patterns. CSCE Lecture 17-10/28/2015 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson) Design Patterns CSCE 740 - Lecture 17-10/28/2015 (Partially adapted from Head First Design Patterns by Freeman, Bates, Sierra, and Robson) OO Design Exercise: Building a Better Duck Duck quack() swim()

More information

Applying the Decorator Design Pattern

Applying the Decorator Design Pattern Applying the Decorator Design Pattern Trenton Computer Festival Professional Seminars Michael P. Redlich (908) 730-3416 michael.p.redlich@exxonmobil.com About Myself Degree B.S. in Computer Science Rutgers

More information

Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter

Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter Design Patterns: Composite, Memento, Template Method, Decorator, Chain of Responsibility, Interpreter Composite Outline for Week 14 [Skrien 8.7] We need to allow users to group figures together to make

More information

CS427a: Object-Oriented Programming Design Patterns for Flexible and Reusable design

CS427a: Object-Oriented Programming Design Patterns for Flexible and Reusable design CS427a: Object-Oriented Programming Design Patterns for Flexible and Reusable design Michael J. Fischer (from slides by Y. Richard Yang) Lecture 23b November 29, 2011 Example: Duck Game A startup produces

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Decorator 1 2 3 4 Decorator Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Decorator 1 An example 2 Your first idea of implementation 3 In reality 4 Now a beverage can be mixed from different condiment to form a new beverage 5 6

More information

More Patterns. Acknowledgement: Head-first design patterns

More Patterns. Acknowledgement: Head-first design patterns More Patterns Acknowledgement: Head-first design patterns Chain of Responsibility Acknowledgement: Head-first design patterns Problem Scenario: Paramount Pictures has been getting more email than they

More information

Writing your own Java I/O Decorator p. 102 Tools for your Design Toolbox p. 105 Exercise Solutions p. 106 The Factory Pattern Baking with OO

Writing your own Java I/O Decorator p. 102 Tools for your Design Toolbox p. 105 Exercise Solutions p. 106 The Factory Pattern Baking with OO Intro to Design Patterns Welcome to Design Patterns: Someone has already solved your problems The SimUDuck app p. 2 Joe thinks about inheritance... p. 5 How about an interface? p. 6 The one constant in

More information

Template Method. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 24 11/15/2007. University of Colorado, 2007

Template Method. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 24 11/15/2007. University of Colorado, 2007 Template Method Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 24 11/15/2007 University of Colorado, 2007 1 Lecture Goals Cover Material from Chapter 8 of the Design Patterns

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 Cont. CSE 110 Discussion - Week 9

Design Patterns Cont. CSE 110 Discussion - Week 9 Design Patterns Cont. CSE 110 Discussion - Week 9 Factory Method - Decouple object creation from implementation details - Allows you to use an object ( product ) without knowing about creation - Often

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Decorator 1 Decorator Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending

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

COMP 6471 Software Design Methodologies

COMP 6471 Software Design Methodologies COMP 6471 Software Design Methodologies Fall 2011 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/comp6471-fall2011.html Week 8 Outline Software Design Patterns Overview of Patterns Present solutions

More information

Hands-On Design Patterns

Hands-On Design Patterns Hands-On Design Patterns A 2-Day Crash Course Nuno Flores - FEUP Software Engineering Group FEUP Nuno Flores 1 Setup time Registering and signing in Grouping? Environment? Notebooks? Allset? FEUP Nuno

More information

HOW DO WE DESIGN A DESIGN PATTERN?

HOW DO WE DESIGN A DESIGN PATTERN? HOW DO WE DESIGN A DESIGN PATTERN? Designingan Example Client Duck quack() fly() Inheritance allows us to reuse code, but also forces attributes and behavior to the subclasses. WildDuck RedHeadDuck

More information

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Template method 1 Design patterns, Laura Semini, Università di Pisa, Dipartimento di Informatica. Hint The underlying is idea not so different from Factory

More information

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming Goals of Lecture Lecture 27: OO Design Patterns Cover OO Design Patterns Background Examples Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2001 April 24, 2001 Kenneth

More information

Factory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate

Factory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate Factory Method Pattern Creational Intent» Define an interface for creating an object but lets subclasses decide the specific class to instantiate > Delegate creation to the appropriate subclass Also known

More information

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

OODP Session 5a.   Web Page:  Visiting Hours: Tuesday 17:00 to 19:00 OODP Session 5a Next week: Reading week 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

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

CSC207 Week 3. Larry Zhang

CSC207 Week 3. Larry Zhang CSC207 Week 3 Larry Zhang 1 Announcements Readings will be posted before the lecture Lab 1 marks available in your repo 1 point for creating the correct project. 1 point for creating the correct classes.

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

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017 Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)

More information

11/12/12. Objectives DESIGN PATTERNS. Design Pattern. Defined Design Patterns. Applying Design Patterns. Motivating Example

11/12/12. Objectives DESIGN PATTERNS. Design Pattern. Defined Design Patterns. Applying Design Patterns. Motivating Example Objectives Design Patterns Open up Eclipse DESIGN PATTERNS Nov 12, 2012 Sprenkle - CSCI209 1 Nov 12, 2012 Sprenkle - CSCI209 2 Design Pattern General reusable solution to a commonly occurring problem in

More information

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3 Department of Computer Science Tackling Design Patterns Chapter 4: Factory Method design pattern Copyright c 2016 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 4.1 Introduction.................................

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

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Real Application Design Christian Nastasi http://retis.sssup.it/~lipari http://retis.sssup.it/~chris/cpp Scuola Superiore Sant Anna Pisa April 12, 2012 C. Nastasi (Scuola

More information

The Factory Method Design Pattern

The Factory Method Design Pattern The Factory Method Design Pattern Some common applications A factory method is used to create objects, whose subclasses can then override to specify the derived type of product that will be created More

More information

TDDB84 Design Patterns Lecture 10. Prototype, Visitor

TDDB84 Design Patterns Lecture 10. Prototype, Visitor Lecture 10 Prototype, Visitor Peter Bunus Dept of Computer and Information Science Linköping University, Sweden petbu@ida.liu.se Prototype Peter Bunus 2 Prototype Non Software Example Peter Bunus 3 Motivational

More information

TDDB84 Design Patterns Lecture 10. Prototype, Visitor

TDDB84 Design Patterns Lecture 10. Prototype, Visitor Lecture 10 Prototype, Visitor Peter Bunus Dept of Computer and Information Science Linköping University, Sweden petbu@ida.liu.se Prototype Peter Bunus 2 1 Prototype Non Software Example Peter Bunus 3 Motivational

More information

Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009

Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009 Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009 23 Odds and Ends In this lecture, I want to touch on a few topics that we did not have time to cover. 23.1 Factory Methods

More information

Building custom components IAT351

Building custom components IAT351 Building custom components IAT351 Week 1 Lecture 1 9.05.2012 Lyn Bartram lyn@sfu.ca Today Review assignment issues New submission method Object oriented design How to extend Java and how to scope Final

More information

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG. Comp435 Object-Oriented Design Week 11 Computer Science PSU HBG 1 Define an interface for creating an object Let subclasses decide which class to instantiate Defer instantiation to subclasses Avoid the

More information

10 Design: Which classes must be included?

10 Design: Which classes must be included? Decorator Pattern 1 10 Design: Which classes must be included? Story As a user I want a weekend planner so that I can have more fun Scenario Given that I have made a plan When Saturday arrives Then Send

More information

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: has a CSE143 Sp Student. CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches

More information

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: has a CSC Employee. Supervisor CSC 143 Object & Class Relationships Inheritance Reading: Ch. 10, 11 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog

More information

16 Multiple Inheritance and Extending ADTs

16 Multiple Inheritance and Extending ADTs Object-Oriented Design Lecture 16 CS 3500 Fall 2009 (Pucella) Tuesday, Nov 10, 2009 16 Multiple Inheritance and Extending ADTs We looked last time at inheritance and delegation as two ways to reuse implementation

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 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.

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

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

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor CSE 143 Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog Dog

More information

DESIGN PATTERNS. Dominik Škoda CHARLES UNIVERSITY Faculty of Mathematics and Physics

DESIGN PATTERNS. Dominik Škoda   CHARLES UNIVERSITY Faculty of Mathematics and Physics DESIGN PATTERNS http://d3s.mff.cuni.cz Dominik Škoda CHARLES UNIVERSITY Faculty of Mathematics and Physics Design Patterns Standard solution of common problems It is not complete

More information

TDDB84 Design Patterns Lecture 06

TDDB84 Design Patterns Lecture 06 Lecture 06 Mediator, Adapter, Bridge Peter Bunus Dept of Computer and Information Science Linköping University, Sweden petbu@ida.liu.se The Mediator Peter Bunus 2 1 Peter Bunus 3 The Mediator Non Software

More information

Spam. Time: five years from now Place: England

Spam. Time: five years from now Place: England Spam Time: five years from now Place: England Oh no! said Joe Turner. When I go on the computer, all I get is spam email that nobody wants. It s all from people who are trying to sell you things. Email

More information

08. DESIGN PRINCIPLES. Originality is Overrated PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT

08. DESIGN PRINCIPLES. Originality is Overrated PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 08. DESIGN PRINCIPLES Originality is Overrated it s not about doing it your way this week is all about doing it the smarter, faster way. Design principle

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Design Patterns. Design Patterns

Design Patterns. Design Patterns Design Patterns Design Patterns A design pattern is a template solution that developers have refined over time to solve a range of recurring problems Generally object-oriented focus Name that uniquely

More information

Credit is where Credit is Due. Lecture 28: OO Design Heuristics (Part 2) This Lecture. Last Lecture: OO Heuristics. Rules of Thumb

Credit is where Credit is Due. Lecture 28: OO Design Heuristics (Part 2) This Lecture. Last Lecture: OO Heuristics. Rules of Thumb Credit is where Credit is Due Lecture 28: OO Design Heuristics (Part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some material for this lecture is taken

More information

C++ Inheritance and Encapsulation

C++ Inheritance and Encapsulation C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members

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

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns Tecniche di Progettazione: Design Patterns GoF: Startegy 1 Strategy pattern: the duck 2 Strategy pattern: the duck 3 The rubber duck 4 First solution Override fly() Class Rubberduck{ fly() { \\ do nothing

More information

Introduction to Design Patterns

Introduction to Design Patterns Introduction to Design Patterns First, what s a design pattern? a general reusable solution to a commonly occurring problem within a given context in software design It s not a finished design that can

More information

Design Patterns: Template Method, Strategy, State, Bridge

Design Patterns: Template Method, Strategy, State, Bridge Design Patterns: Template Method, Strategy, State, Bridge [HFDP, Ch. 8] Say we have two classes whose code looks similar, but isn t identical. We can duplicate the code, but change it where changes are

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

Inheritance, and Polymorphism.

Inheritance, and Polymorphism. Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to

More information

Functions! Objectives! 1E3! Topic 9! programming! n This topic should allow students to! n Read chapter 6 of the textbook now.!

Functions! Objectives! 1E3! Topic 9! programming! n This topic should allow students to! n Read chapter 6 of the textbook now.! Functions 1E3 Topic 9 9 Functions 1 Objectives n This topic should allow students to n Understand the importance of abstraction in programming n Recognise when a function would be useful. n Design appropriate

More information

C++ Modern and Lucid C++ for Professional Programmers

C++ Modern and Lucid C++ for Professional Programmers Informatik C++ Modern and Lucid C++ for Professional Programmers part 13 Prof. Peter Sommerlad Institutsleiter IFS Institute for Software Rapperswil, HS 2015 Inheritance and dynamic Polymorphism base classes,

More information

Originality is Overrated: OO Design Principles

Originality is Overrated: OO Design Principles Originality is Overrated: OO Design Principles Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 13 10/09/2007 University of Colorado, 2007 1 Lecture Goals Review material from

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.

More information

After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady.

After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady. Introduction After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady. Your theory that the sun is the centre of the solar system, and the earth

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

10. Object-oriented Programming. 7. Juli 2011

10. Object-oriented Programming. 7. Juli 2011 7. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Object Case Study Brain Teaser Copy Constructor & Operators Object-oriented Programming, i.e.

More information

Façade and the DP Wrap-Up

Façade and the DP Wrap-Up Façade and the DP Wrap-Up 1 Which pattern does this class diagram from the Factory chapter call out for? A. Strategy B. Decorator C. Adapter D. Factory 2 B: Decorator Discussion We see a combinatorial

More information

PHP Syntax. PHP is a great example of a commonly-used modern programming language.

PHP Syntax. PHP is a great example of a commonly-used modern programming language. PHP is a great example of a commonly-used modern programming language. C was first released in 1972, PHP in 1995. PHP is an excellent language choice for software that requires an easy way to do things

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

Creating an HTML file (Mac)

Creating an HTML file (Mac) writing html on a macintosh Creating an HTML file (Mac) All HTML files are text files. To create a text file you need an application that allows you to create plain text without throwing in a lot of fancy

More information

The Factory Pattern. Ballplayer joe = new Ballplayer("Dimaggio","OF");

The Factory Pattern. Ballplayer joe = new Ballplayer(Dimaggio,OF); Chapter 10 The Factory Pattern Now that we ve covered inheritance, we re in a position to understand the next simple-yet-ubiquitous design pattern, called Factory. It s a pretty easy one to grasp. Simply

More information

What is Design Patterns?

What is Design Patterns? Paweł Zajączkowski What is Design Patterns? 1. Design patterns may be said as a set of probable solutions for a particular problem which is tested to work best in certain situations. 2. In other words,

More information

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 1 Problem Ralph owns the Trinidad Fruit Stand that sells its fruit on the street, and he wants to use a computer

More information

Common Architectures and Design Patterns

Common Architectures and Design Patterns Common Architectures and Design Patterns 1 Architectural Styles High-level abstractions of components and communication Even higher than data types, algorithmic pseudocode Also known as design patterns

More information

Quarter 1 Practice Exam

Quarter 1 Practice Exam University of Chicago Laboratory Schools Advanced Placement Computer Science Quarter 1 Practice Exam Baker Franke 2005 APCS - 12/10/08 :: 1 of 8 1.) (10 percent) Write a segment of code that will produce

More information

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive

More information

Singleton vs. Global Variable

Singleton vs. Global Variable Singleton vs. Global Variable A global variable is always instantiated. A singleton is generally instantiated only if it's actually needed. Global variables are initialized before the program starts. Some

More information

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4 CS32 - Week 4 Umut Oztok Jul 15, 2016 Inheritance Process of deriving a new class using another class as a base. Base/Parent/Super Class Derived/Child/Sub Class Inheritance class Animal{ Animal(); ~Animal();

More information

GENERAL MATH FOR PASSING

GENERAL MATH FOR PASSING GENERAL MATH FOR PASSING Your math and problem solving skills will be a key element in achieving a passing score on your exam. It will be necessary to brush up on your math and problem solving skills.

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

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

Introduction to Inheritance

Introduction to Inheritance INHERITANCE Introduction to Inheritance Inheritance is a relationship between two or more classes where derived class inherites behaviour and attributes of pre-existing (base) classes Intended to help

More information

CS11 Introduction to C++ Fall Lecture 7

CS11 Introduction to C++ Fall Lecture 7 CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,

More information

Design patterns. Jef De Smedt Beta VZW

Design patterns. Jef De Smedt Beta VZW Design patterns Jef De Smedt Beta VZW Who Beta VZW www.betavzw.org Association founded in 1993 Computer training for the unemployed Computer training for employees (Cevora/Cefora) 9:00-12:30 13:00-16:00

More information

CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers

CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 2 with Answers This was a 100-minute open-book test. There were a total of 105 points on this test.. If you answered more than 100% worth

More information

Table of Contents (summary) Table of Contents (the real thing)

Table of Contents (summary) Table of Contents (the real thing) Table of Contents (summary) Intro xxv 1 Welcome to Design Patterns: an introduction 1 2 Keeping your Objects in the know: the Observer Pattern 37 3 Decorating Objects: the Decorator Pattern 79 4 Baking

More information

Object-Oriented Concepts and Design Principles

Object-Oriented Concepts and Design Principles Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation

More information