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

Size: px
Start display at page:

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

Transcription

1 Lecture 05 Builder, Singleton, Proxy Peter Bunus Dept of Computer and Information Science Linköping University, Sweden

2 The Constitution of Software Architects Encapsulate what varies. Program to an interface not to an implementation. Favor Composition over Inheritance. Classes should be open extension but closed for modification Don t call us, we ll call you A Class should have only one reason to change Depend upon abstractions. Do not depend upon concrete classes.?????????????????? Peter Bunus 2

3 The Builder Pattern Peter Bunus 3

4 The Builder - Intent Separate the construction of a complex object from its representation so that the same construction process can create different representations. A client uses the builder pattern like an individual would use an interior designer and furniture maker to build furniture - the individual (Client) tells the designer what he wants, and the designer (Director), the furniture maker (Builder), and his tool (Concrete builders) create the furniture (Product) Peter Bunus 4

5 Builder - Example 1) The boss tells Joe what he wants Director Builder 3) Joe tells the furniture maker to build a chair. Note that the furniture maker could have also built a beach furniture or a skateboard. 1) The boss wants some new furniture. He calls his direct aid. Concrete Builder1 Concrete Builder2 Concrete Builder1 Client Product 3) The boss gets the armchair produced by the furniture maker and his tools Peter Bunus 5

6 Why Use Builder? Use the builder pattern when: The algorithm for creating a complex object should be independent of the parts that make up the object and how they are assembled The construction process must allow different representations for the object that s constructed Builder is very useful because it allows the program to create a flexible number of objects you can add or delete objects as necessary Peter Bunus 6

7 Builder Non Software Example Peter Bunus 7

8 The Builder Design Pattern Separate the construction of a complex object from its representation so that the same construction process can create different representations. The client creates the Director object and configures it with the desired Builder object. Director notifies the builder whenever a part of the product should be built. Builder handles requests from the director and adds parts to the product. The client retrieves the product from the builder. Peter Bunus 8

9 Builder - Example Peter Bunus 9

10 Consequences of the Builder Pattern A Builder lets you vary the internal representation of the product it builds. It also hides the details of how the product is assembled. Each specific builder is independent of the others and of the rest of the program. This improves modularity and makes the addition of other builders relatively simple. Because each builder constructs the final product step-by-step, depending on the data, you have more control over each final product that a Builder constructs. A Builder pattern is somewhat like an Abstract Factory pattern in that both return classes made up of a number of methods and objects. The main difference is that while the Abstract Factory returns a family of related classes, the Builder constructs a complex object step by step depending on the data presented to it. Peter Bunus 10

11 Builder vs. Abstract Factory Return classes made up of a number of methods and objects Builder constructs a complex object step by step depending on the data presented to it. Return classes made up of a number of methods and objects Builder Abstract Factory returns a family of related classes Abstract Factory Peter Bunus 11

12 The Singleton Pattern Peter Bunus 12

13 A Java Programming Exercise How you would create a Duck object? new MyDuck What if somebody else would like to create a Duck object as well? Could she/he call the new on MyDuck again? Yes, why not An how about now? private MyDuck{ Well, only classes in the same package can instantiate it Peter Bunus 13

14 A Java Programming Exercise Did you know you could do this? public MyDuck{ private MyDuck(){ You can t instantiate this class because it has a private constructor Wait a minute... MyDuck can call its private contsructor. But I need to have an instance to call it Ok, What does this mean? public MyDuck{ public static MyDuck getinstance(){ MyDuck.getInstance() Wonderfull getinstance() is a static method. One uses the class name to reference a static method Peter Bunus 14

15 A Java Programming Exercise public MyDuck{ private MyDuck(){ public MyDuck{ public static MyDuck getinstance(){ public MyDuck{ private MyDuck(){ public static MyDuck getinstance(){ return new MyDuck(); How you would create a Duck object now? MyDuck.getInstance() Peter Bunus 15

16 A Java Programming Exercise Can you create now more than one Ducks? public MyDuck{ private MyDuck(){ public static MyDuck getinstance(){ Yes, why not return new MyDuck(); public MyDuck{ But I Would like to have only one Duck private static MyDuck oneduck; How you do it? private MyDuck(){ public static MyDuck getinstance(){ if (oneduck == null){ oneduck = new MyDuck(); return oneduck; Peter Bunus 16

17 A C++ Programming Exercise class MyDuck{ public: static MyDuck* getinstance(); protected: MyDuck(); private: static MyDuck * oneduck; MyDuck* MyDuck::oneDuck = 0; MyDuck * MyDuck ::getinstance () { if (oneduck == 0) { oneduck = new MyDuck; return oneduck; Peter Bunus 17

18 Election Day public class PrimeMinister{ private boolean speech; private boolean cabinet; public PrimeMinister(){ speech = false; cabinet = true; public void writespeech(){ // write the speech here speech = true public void deliverspeech(){ if (speech==true){ //deliver speech for the parlament speech = false; public void formcabinet(){ if (cabinet == true){ //form the governement cabinet cabinet = false Peter Bunus 18

19 Help the Electors Could you make sure that only one Prime minister is elected by turning our class into a singleton public class PrimeMinister{ private boolean speech; private boolean cabinet; private static PrimeMinister uniquepm private public PrimeMinister(){ speech = false; cabinet = true; public void writespeech(){ // write the speech here speech = true public void deliverspeech(){ if (speech==true){ //deliver speech for the parlament speech = false; public static PrimeMinister getelected(){ if(uniquepm == null){ uniquepm = new PrimeMinister(); return uniquepm; Peter Bunus 19

20 The Election on Java Island Went Wrong Mayday, Mayday. We just finished our multithreaded election and now there are two guys delivering speeches and forming a government. What happened? You were suppose to deliver me a singleton class. PrimeMinister pm = PrimeMinister.getElected(); formcabinet(); writespeech(); deliverspeech(); Peter Bunus 20

21 What happened? Thread 1 Thread 2 Value of uniquepm public static PrimeMinister getelected(){ public static PrimeMinister getelected(){ if (uniquepm == null){ if (uniquepm == null){ uniquepm = new PrimeMinister() return = uniquepm; uniquepm = new PrimeMinister() return = uniquepm; Peter Bunus 21

22 Syncronizing the Multithreaded Elections public static syncronized PrimeMinister getelected(){ if(uniquepm == null){ uniquepm = new PrimeMinister(); return uniquepm; public static PrimeMinister getelected(){ Thread 1 Thread 2 By adding the syncronized keyword to getelected() we force every thread to wait its turn before it can enter the method. This is no two thread may enter the method at the same time Value of uniquepm if (uniquepm == null){ uniquepm = new PrimeMinister( ) return = uniquepm; public static PrimeMinister getelected(){ if (uniquepm == null){ uniquepm = new PrimeMinister( ) return = uniquepm; Peter Bunus 22

23 Singleton Non Software Example Peter Bunus 23

24 The Singleton Pattern Ensure a class only has one instance, and provide a global point of access to it. Peter Bunus 24

25 Summary of Creational Patterns The Factory Pattern is used to choose and return an instance of a class from a number of similar classes based on data you provide to the factory. The Abstract Factory Pattern is used to return one of several groups of classes. In some cases it actually returns a Factory for that group of classes. The Builder Pattern assembles a number of objects to make a new object, based on the data with which it is presented. Frequently, the choice of which way the objects are assembled is achieved using a Factory. The Singleton Pattern is a pattern that insures there is one and only one instance of an object, and that it is possible to obtain global access to that one instance. Peter Bunus 25

26 The Proxy Pattern Peter Bunus 26

27 The Proxy Pattern (prok-se) An agent or substitute authorized to act for another What is expensive? Object Creation Object Initialization Defer object creation and object initialization to the time you need the object Proxy pattern: Reduces the cost of accessing objects Uses another object ( the proxy ) that acts as a stand-in for the real object The proxy creates the real object only if the user asks for it Peter Bunus 27

28 Proxy - Example Peter Bunus 28

29 Proxy Example Peter Bunus 29

30 Proxy Non Software Example Peter Bunus 30

31 The Proxy Pattern Here's a possible object diagram of a proxy structure at run-time: Peter Bunus 31

32 The Proxy Pattern - Example Peter Bunus 32

33 A Proxy Image Example We would like to create a simple program to display an image on a JPanel when it is loaded. Rather than loading the image directly, we use a class we call ImageProxy to defer loading and draw a rectangle around the image area until loading is completed. Peter Bunus 33

34 A Proxy Image Example public class ProxyDisplay extends JxFrame { public ProxyDisplay() { super("display proxied image"); JPanel p = new JPanel(); getcontentpane().add(p); p.setlayout(new BorderLayout()); ImageProxy image = new ImageProxy("elliott.jpg", 321, 271); p.add("center", image); p.add("north", new Label(" ")); p.add("west", new Label(" ")); setsize(370, 350); setvisible(true); // static public void main(string[] argv) { new ProxyDisplay(); Peter Bunus 34

35 A Proxy Image Example public ImageProxy(String filename, int w, int h) { height = h; width = w; tracker = new MediaTracker(this); img = Toolkit.getDefaultToolkit().getImage(filename); tracker.addimage(img, 0); //watch for image loading imagecheck = new Thread(this); imagecheck.start(); //start 2nd thread monitor //this begins actual image loading try{ tracker.waitforid(0,1); catch(interruptedexception e){ Peter Bunus 35

36 A Proxy Image Example public void run() { //this thread monitors image loading //and repaints when done //the 1000 msec is artifically long //to allow demo to display with delay try{ Thread.sleep(1000); while(! tracker.checkid(0)) Thread.sleep(1000); catch(exception e){ repaint(); Peter Bunus 36

37 A Proxy Image Example public void paint(graphics g) { if (tracker.checkid(0)) { height = img.getheight(frame); //get height width = img.getwidth(frame); //and width g.setcolor(color.lightgray); //erase box g.fillrect(0,0, width, height); g.drawimage(img, 0, 0, this); //draw loaded image else { //draw box outlining image if not loaded yet g.setcolor(color.black); g.drawrect(1, 1, width-2, height-2); Peter Bunus 37

Strategy Pattern. What is it?

Strategy Pattern. What is it? Strategy Pattern 1 What is it? The Strategy pattern is much like the State pattern in outline, but a little different in intent. The Strategy pattern consists of a number of related algorithms encapsulated

More information

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

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

More information

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it

Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it Design Patterns The Gang of Four suggests a few strategies for creating good o-o designs, including Façade Design to interfaces. Favor composition over inheritance Find what varies and encapsulate it One

More information

Singleton Pattern Creational

Singleton Pattern Creational Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecturer: Raman Ramsin Lecture 20: GoF Design Patterns Creational 1 Software Patterns Software Patterns support reuse of software architecture and design. Patterns capture the static

More information

Software Design COSC 4353/6353 D R. R A J S I N G H

Software Design COSC 4353/6353 D R. R A J S I N G H Software Design COSC 4353/6353 D R. R A J S I N G H Creational Design Patterns What are creational design patterns? Types Examples Structure Effects Creational Patterns Design patterns that deal with object

More information

The Singleton Pattern. Design Patterns In Java Bob Tarr

The Singleton Pattern. Design Patterns In Java Bob Tarr The Singleton Pattern Intent Ensure a class only has one instance, and provide a global point of access to it Motivation Sometimes we want just a single instance of a class to exist in the system For example,

More information

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern. Proxy : Motivation Design s 2 It is 3pm. I am sitting at my 10Mbps connection and go to browse a fancy web page from the US, This is prime web time all over the US. So I am getting 100kbps What can you

More information

TDDB84: Lecture 5. Singleton, Builder, Proxy, Mediator. fredag 27 september 13

TDDB84: Lecture 5. Singleton, Builder, Proxy, Mediator. fredag 27 september 13 TDDB84: Lecture 5 Singleton, Builder, Proxy, Mediator Creational Abstract Factory Singleton Builder Structural Composite Proxy Bridge Adapter Template method Behavioral Iterator Mediator Chain of responsibility

More information

CHAPTER 6: CREATIONAL DESIGN PATTERNS

CHAPTER 6: CREATIONAL DESIGN PATTERNS CHAPTER 6: CREATIONAL DESIGN PATTERNS SESSION III: BUILDER, PROTOTYPE, SINGLETON Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E. Otero For non-profit

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

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

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

Lecture 06: Classes and Objects

Lecture 06: Classes and Objects Accelerating Information Technology Innovation http://aiti.mit.edu Lecture 06: Classes and Objects AITI Nigeria Summer 2012 University of Lagos. What do we know so far? Primitives: int, float, double,

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

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

Design Pattern- Creational pattern 2015

Design Pattern- Creational pattern 2015 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are created composed represented Encapsulates knowledge about which concrete classes the system uses Hides

More information

Material and some slide content from: - GoF Design Patterns Book. Design Patterns #1. Reid Holmes. Lecture 11 - Tuesday October

Material and some slide content from: - GoF Design Patterns Book. Design Patterns #1. Reid Holmes. Lecture 11 - Tuesday October Material and some slide content from: - GoF Design Patterns Book Design Patterns #1 Reid Holmes Lecture 11 - Tuesday October 19 2010. GoF design patterns!"#$%&'()*$+,--&.*' /.&,-("*,0 1-.23-2.,0 4&5,6(".,0

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

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

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

More information

Lecture 7 Objects and Classes

Lecture 7 Objects and Classes Lecture 7 Objects and Classes An Introduction to Data Abstraction MIT AITI June 13th, 2005 1 What do we know so far? Primitives: int, double, boolean, String* Variables: Stores values of one type. Arrays:

More information

TDDB84 Design Patterns Lecture 02. Factory Method, Decorator

TDDB84 Design Patterns Lecture 02. Factory Method, Decorator Lecture 02 Factory Method, Decorator Peter Bunus Dept of Computer and Information Science Linköping University, Sweden petbu@ida.liu.se Factory Method Pattern Peter Bunus 2 1 Time for Lunch Joe, with the

More information

A few important patterns and their connections

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

More information

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

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

More information

The Singleton Pattern. Design Patterns In Java Bob Tarr

The Singleton Pattern. Design Patterns In Java Bob Tarr The Singleton Pattern Intent Ensure a class only has one instance, and provide a global point of access to it Motivation Sometimes we want just a single instance of a class to exist in the system For example,

More information

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

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

More information

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13 TDDB84: Lecture 6 Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command Creational Abstract Factory Singleton Builder Structural Composite Proxy Bridge Adapter Template method Behavioral

More information

TWO-DIMENSIONAL FIGURES

TWO-DIMENSIONAL FIGURES TWO-DIMENSIONAL FIGURES Two-dimensional (D) figures can be rendered by a graphics context. Here are the Graphics methods for drawing draw common figures: java.awt.graphics Methods to Draw Lines, Rectangles

More information

CPSC 310 Software Engineering. Lecture 11. Design Patterns

CPSC 310 Software Engineering. Lecture 11. Design Patterns CPSC 310 Software Engineering Lecture 11 Design Patterns Learning Goals Understand what are design patterns, their benefits and their drawbacks For at least the following design patterns: Singleton, Observer,

More information

3. Which software architecture do you think most closely resembles your Wildfire or Drought system and why?

3. Which software architecture do you think most closely resembles your Wildfire or Drought system and why? CS 4667 Software Engineering Exam #2 System Design, Object Design, Mapping models to code Take home format (individual assignment) Handed out: Mon 19 Nov 2007 1pm DUE: Mon 26 Nov 2007 1pm Returned: Fri

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

Concurrency: State Models & Design Patterns

Concurrency: State Models & Design Patterns Concurrency: State Models & Design Patterns Practical Session Week 02 1 / 13 Exercises 01 Discussion Exercise 01 - Task 1 a) Do recent central processing units (CPUs) of desktop PCs support concurrency?

More information

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java 1 CS/ENGRD 2110 SPRING 2014 Lecture 2: Objects and classes in Java http://courses.cs.cornell.edu/cs2110 Java OO (Object Orientation) 2 Python and Matlab have objects and classes. Strong-typing nature of

More information

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

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

More information

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

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

More information

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

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

IT101. Graphical User Interface

IT101. Graphical User Interface IT101 Graphical User Interface Foundation Swing is a platform-independent set of Java classes used for user Graphical User Interface (GUI) programming. Abstract Window Toolkit (AWT) is an older Java GUI

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Bh Solution Sheet 4 Software Engineering in Java This is a solution set for CS1Bh Question Sheet 4. You should only consult these solutions after attempting the exercises. Notice that the solutions

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

SDC Design patterns GoF

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

More information

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

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

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

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

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017 Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data

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 Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) Design Pattern CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) A. Design Pattern Design patterns represent the best practices used by experienced

More information

Object-oriented Software Design Patterns

Object-oriented Software Design Patterns Object-oriented Software Design Patterns Concepts and Examples Marcelo Vinícius Cysneiros Aragão marcelovca90@inatel.br Topics What are design patterns? Benefits of using design patterns Categories and

More information

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled

More information

A Reconnaissance on Design Patterns

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

More information

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

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

More information

1.00 Lecture 8. Using An Existing Class, cont.

1.00 Lecture 8. Using An Existing Class, cont. .00 Lecture 8 Classes, continued Reading for next time: Big Java: sections 7.9 Using An Existing Class, cont. From last time: is a Java class used by the BusTransfer class BusTransfer uses objects: First

More information

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, WINTER TERM, 2012 FINAL EXAMINATION 9am to 12pm, 26 APRIL 2012 Instructor: Alan McLeod If the instructor is

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

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z) Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali Valentina Presutti (A-L) Riccardo Solmi (M-Z) Indice degli argomenti Catalogo di Design Patterns creazionali: Abstract Factory

More information

Dealing with Bugs. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009

Dealing with Bugs. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009 Dealing with Bugs Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009 University of Colorado, 2009 1 Goals 2 Review material from Chapter 11 of Pilone & Miles Dealing with

More information

ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns

ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/60 ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns Professor Jia Wang Department of Electrical

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

Software Quality Management

Software Quality Management 2004-2005 Marco Scotto (Marco.Scotto@unibz.it) Course Outline Creational Patterns Singleton Builder 2 Design pattern space Purpose Creational Structural Behavioral Scope Class Factory Method Adapter Interpreter

More information

The AWT Package, Graphics- Introduction to Images

The AWT Package, Graphics- Introduction to Images Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, Graphics- Introduction to Images Java Programming, Lecture Notes # 170, Revised 09/23/98.

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 Sample Solution

CSE wi Final Exam 3/12/18 Sample Solution Question 1. (8 points, 2 each) Equality. Recall that there are several different notions of object equality that we ve encountered this quarter. In particular, we have the following three: Reference equality:

More information

52 Franck van Breugel and Hamzeh Roumani

52 Franck van Breugel and Hamzeh Roumani 52 Franck van Breugel and Hamzeh Roumani Chapter 3 Mixing Static and Non-Static Features 3.1 Introduction In Chapter 1, we focused on static features. Non-static features were the topic of Chapter 2. In

More information

5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16]

5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16] Code No: R05220402 Set No. 1 1. (a) java is freeform language. Comment (b) Describe in detail the steps involved in implementing a stand-alone program. (c) What are command line arguments? How are they

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

» Reader for RTF (Rich Text Format) should be able to convert to any other representation Plain Text, MIF (Maker Interchange File), Postscript

» Reader for RTF (Rich Text Format) should be able to convert to any other representation Plain Text, MIF (Maker Interchange File), Postscript Builder Pattern Creational Intent Separate the construction of a complex object from its representation so that the same construction process can create different representations Motivation» Reader for

More information

Design Pattern Examples

Design Pattern Examples Factory Pattern (Creational) Design Pattern Examples Goal: Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate. The Factory method

More information

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU) Creational Patterns Creational Patterns Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU) Factory Method (FM) Intent: Define an interface for creating an object, but

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

CPS221 Lecture: Threads

CPS221 Lecture: Threads Objectives CPS221 Lecture: Threads 1. To introduce threads in the context of processes 2. To introduce UML Activity Diagrams last revised 9/5/12 Materials: 1. Diagram showing state of memory for a process

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

GOF Patterns Applied

GOF Patterns Applied www.teamsoftinc.com GOF Patterns Applied Kirk Knoernschild TeamSoft, Inc. www.teamsoftinc.com http://techdistrict.kirkk.com http://www.kirkk.com pragkirk@kirkk.com GOF Patterns in Java Pattern Review The

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

The Proxy Pattern. Design Patterns In Java Bob Tarr

The Proxy Pattern. Design Patterns In Java Bob Tarr The Proxy Pattern Intent Provide a surrogate or placeholder for another object to control access to it Also Known As Surrogate Motivation A proxy is a person authorized to act for another person an agent

More information

Lecture 6 Introduction to Objects and Classes

Lecture 6 Introduction to Objects and Classes Lecture 6 Introduction to Objects and Classes Outline Basic concepts Recap Computer programs Programming languages Programming paradigms Object oriented paradigm-objects and classes in Java Constructors

More information

The Design Patterns Matrix From Analysis to Implementation

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

More information

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday! Lab & Assignment 1 Lecture 3: ArrayList & Standard Java Graphics CS 62 Fall 2015 Kim Bruce & Michael Bannister Strip with 12 squares & 5 silver dollars placed randomly on the board. Move silver dollars

More information

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java 1 CS/ENGRD 2110 SPRING 2017 Lecture 2: Objects and classes in Java http://courses.cs.cornell.edu/cs2110 CMS VideoNote.com, PPT slides, DrJava, Book 2 CMS available. Visit course webpage, click Links, then

More information

Reuse at Design Level: Design Patterns

Reuse at Design Level: Design Patterns Reuse at Design Level: Design Patterns CS 617- Lecture 17 Mon. 17 March 2008 3:30-5:00 pm Rushikesh K. Joshi Department of Computer Sc. & Engg. Indian Institute of Technology, Bombay Mumbai - 400 076 Reuse

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

Sample Examination Paper Programming and Software Development

Sample Examination Paper Programming and Software Development THE UNIVERSITY OF MELBOURNE DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Sample Examination Paper 2008 433-520 Programming and Software Development Exam Duration: 2 hours Total marks for this

More information

JAVA GUI PROGRAMMING REVISION TOUR III

JAVA GUI PROGRAMMING REVISION TOUR III 1. In java, methods reside in. (a) Function (b) Library (c) Classes (d) Object JAVA GUI PROGRAMMING REVISION TOUR III 2. The number and type of arguments of a method are known as. (a) Parameter list (b)

More information

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005 Lecture 8 Classes and Objects Part 2 MIT AITI June 15th, 2005 1 What is an object? A building (Strathmore university) A desk A laptop A car Data packets through the internet 2 What is an object? Objects

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

MSO Object Creation Singleton & Object Pool

MSO Object Creation Singleton & Object Pool MSO Object Creation Singleton & Object Pool Wouter Swierstra & Hans Philippi October 25, 2018 Object Creation: Singleton & Object Pool 1 / 37 This lecture How to create objects The Singleton Pattern The

More information

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012 CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012 Name: This exam consists of 6 problems on the following 8 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

Recitation 3 Class and Objects

Recitation 3 Class and Objects 1.00/1.001 Introduction to Computers and Engineering Problem Solving Recitation 3 Class and Objects Spring 2012 1 Scope One method cannot see variables in another; Variables created inside a block: { exist

More information

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name: CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides

More information

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009 CS 349 / SE 382 Design Patterns Professor Michael Terry January 21, 2009 Today s Agenda More demos! Design patterns CS 349 / SE 382 / 2 Announcements Assignment 1 due Monday at 5PM! CS 349 / SE 382 / 3

More information

Java Foundations. 7-2 Instantiating Objects. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Java Foundations. 7-2 Instantiating Objects. Copyright 2015, Oracle and/or its affiliates. All rights reserved. Java Foundations 7-2 Copyright 2015, Oracle and/or its affiliates. All rights reserved. Objectives This lesson covers the following objectives: Understand the memory consequences of instantiating objects

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

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

Aggregation. Introduction to Computer Science I. Overview (1): Overview (2): CSE 1020 Summer Bill Kapralos. Bill Kapralos.

Aggregation. Introduction to Computer Science I. Overview (1): Overview (2): CSE 1020 Summer Bill Kapralos. Bill Kapralos. Aggregation Thursday, July 6 2006 CSE 1020, Summer 2006, Overview (1): Before We Begin Some administrative details Some questions to consider Aggregation Overview / Introduction The aggregate s constructor

More information

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017 1 MSO Lecture 12 Wouter Swierstra (adapted by HP) October 26, 2017 2 LAST LECTURE Analysis matrix; Decorator pattern; Model-View-Controller; Observer pattern. 3 THIS LECTURE How to create objects 4 CATEGORIES

More information

Example: Fibonacci Numbers

Example: Fibonacci Numbers Example: Fibonacci Numbers Write a program which determines F n, the (n + 1)-th Fibonacci number. The first 10 Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The sequence of Fibonacci numbers

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 2 Processes & Threads Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of this lecture Java implementations of concurrency process and threads

More information