TDDB84 Design Patterns Exam



Similar documents
Tentamen NGP012 Systemarkitektprogrammet. 24 poäng

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

DECISION/BESLUT

Tanden Care Provider Interfaces PreAssessmentSTB v3

Domains and Competencies

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park

Tanden Care Provider Interfaces Reverse Claim v1

Java EE Web Development Course Program

Contents. Introduction and System Engineering 1. Introduction 2. Software Process and Methodology 16. System Engineering 53

How To Use The Command Pattern In Java.Com (Programming) To Create A Program That Is Atomic And Is Not A Command Pattern (Programmer)

Demo Gotland (Smart Customer Gotland)

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

Object Oriented Software Models

Engelsk Grammatik. Namn: Personnummer: Institutionens anteckningar: Maxpoäng: 62 Din poäng: Betyg:

10CS35: Data Structures Using C

Patterns in. Lecture 2 GoF Design Patterns Creational. Sharif University of Technology. Department of Computer Engineering

Java Application Developer Certificate Program Competencies

9 Marital status Single Married Separated Divorced Widow(er) * 19 Current occupation Valid: From

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Bachelor of Games and Virtual Worlds (Programming) Subject and Course Summaries

Analysis of Binary Search algorithm and Selection Sort algorithm

Java (12 Weeks) Introduction to Java Programming Language

Curriculum Map. Discipline: Computer Science Course: C++

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

GCE Computing. COMP3 Problem Solving, Programming, Operating Systems, Databases and Networking Report on the Examination.

AP Computer Science AB Syllabus 1

Algorithms and Data Structures Written Exam Proposed SOLUTION

Computer Programming I

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

How To Design Your Code In Php (Php)

Chapter 1: Key Concepts of Programming and Software Engineering

USER GUIDE Appointment Manager

Programming and Software Development CTAG Alignments

Sweden National H.O.G. Rally July 2010

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

C++ Programming Language

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Vector storage and access; algorithms in GIS. This is lecture 6

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Foundations of Programming

MF2019, CAD 3D-modeling och visualization Spring 2011 PROJECT

Vet du redan nu att du vill studera på Emirates Academy kan du fylla i ansökan nedan och skicka till KILROY.

Projektet Computer: Specifikation. Objektorienterad modellering och diskreta strukturer / design. Projektet Computer: Data. Projektet Computer: Test

Skills for Employment Investment Project (SEIP)

11 November

2) What is the structure of an organization? Explain how IT support at different organizational levels.

Android Application Development Course Program

MAXimize the benefits of Mobility Management

IB Maths SL Sequence and Series Practice Problems Mr. W Name

Binary Heap Algorithms

PRTK. Password Recovery ToolKit EFS (Encrypting File System)

Design Suggestions for Danske Bank SE

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

3gamma Från traditionell IT-leverans till modern, processtyrd tjänsteleverans i en multi-sourcing miljö. Peter Wahlgren, September 2013

Data Structures. Level 6 C Module Descriptor

CSE 1020 Introduction to Computer Science I A sample nal exam

Panthera - A Helpdesk System developed in Visual Studio.NET

CS193j, Stanford Handout #10 OOP 3

Java the UML Way: Integrating Object-Oriented Design and Programming

PES Institute of Technology-BSC QUESTION BANK

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Tanden Care Provider Interfaces Submit Claim v3

Fundamentals of Java Programming

Questionnaire for visa applicants Appendix A

Project 2: Character Animation Due Date: Friday, March 10th, 11:59 PM

Application Note C++ Debugging

SAS Education Providing knowledge through global training and certification. SAS Foundation. Kursöversikt 2010

Cpt S 223. School of EECS, WSU

Readme10_054.doc page 1 of 7

Effektiv hantering av Data och Information i M3 Joakim Jannerfeldt Anders Cottman

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Application for Schengen Visa

Tentamen i GRUNDLÄGGANDE MATEMATISK FYSIK

Data Structures. Algorithm Performance and Big O Analysis

PING PONG Help and Manuals

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Java Software Structures

MATHEMATICS Unit Decision 1

50 Computer Science MI-SG-FLD050-02

Sickness benefit [Sjukpenning]

ATM Case Study OBJECTIVES Pearson Education, Inc. All rights reserved Pearson Education, Inc. All rights reserved.

User's Manual SAM 2.7 PPC 5.3.3

Glossary of Object Oriented Terms

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

Transcription:

TDDB84 Design Patterns Exam Tid: 14-18 October 15, 2005 Place: Ter1 (Terra) Skriv namn, klass, och personnummer på samtliga lösa blad. Poängavdrag kommer att göras om punkterna nedan inte åtföljs! Write name, class, and person number on all solution sheets. Please also observe the following, otherwise it might lead to subtraction of points. 1) Endast ett svar per blad. Använd endast framsidan (delfrågor kan vara på samma sida). Write only the answer to one task on one sheet. Use only the front side of the sheets (answers to subtasks can be on one page). 2) Sortera inlämnade svar med avseende på uppgiftsnummer i stigande ordning. Sort the solution sheets according to the task number. 3) Svaren får vara på svenska eller engelska. Answers may be in English or Swedish. 4) Dina svar skall tydligt visa lösningsmetod. Enbart rätt svar kommer inte att ge poäng. I det fall du är osäker på frågeställning, skriv ner din tolkning och lös uppgiften utifrån din tolkning. Your answers should clearly show solution methods, reasons, and arguments. Short answers should be motivated. If you are in doubt, write a remark. 5) Som hjälpmedel är boken av Gamma eller liknande INTE tillåtna. The Gamma book and the articles are NOT allowed. 1 Singleton (3 points) Give an example where the Singleton design pattern would be useful. 2 Design patterns general knowledge (10 points) Having the following design patterns, please partition them into: creational design patterns, structural design patterns and behavioral design patterns: (a) Abstract Factory (b) Facade (c) Proxy (d) Singleton (e) Observer (f) Prototype 3 Design pattern characteristics (10 points) What are the common and different characteristics of the Bridge and the Strategy design patterns?

4 Shell command (2 point) Which design pattern is used by your shell to realize a command like: ls l * cut f1,2 sort Observation: It is totally irrelevant what the three commands do, and you do not even need to know what they are doing. 5 Design Pattern recognition (10 points) Consider the following UML diagram. View models Model -models : Model +Attach() +Detach() +Notify() for all m in models m->update() +Update() ConcreteModel ConcreteView -state +GetState() +SetState() return state view -state -view : ConcreteView +Update() state = view->getstate() (a) First, identify the pattern in the diagram. (b) Second, identify the participants in the diagram and indicate their responsibilities. 6 Evaluation of integer trees (15 points) Consider the following UML diagram. In the ArithmeticExpression the operator is of type char and can have one of the following values: + and -. (a) What pattern is represented by the diagram? (b) Change the class diagram to implement an interpreter over arithmetic expressions. (c) Sketch the methods added to the diagram at section (b) (d) Changes the class diagram obtained in section (b) and add new classes (and methods to the old ones) to implement a visitor over the integer trees. (e) Sketch the new methods added to the class diagram (both for the existing classes and for the new ones) at section (d). For the visitor methods consider just printing out the tree contents.

7 Tetris (5 points) A Tetris field is essentially a big collection of stones, some representing empty fields, and some representing parts of a Tetris block, either just falling or landed at the bottom of the play ground some time ago. Whenever a block lands, it dissembles into its individual stones, which are considered independent from then on. It makes sense, therefore, to represent each stone by an individual object in an object-oriented Tetris application. Doing so naively results in a large amount of objects being allocated, deleted, and moved all the time. Task: What design pattern can be applied to optimize this, taking advantage of the fact that the stones are really very similar? Motivate your answer. 8 Ray-tracing (15 points) Ray-tracing is a technology for generating photo-realistic images from scene description data. Very advanced types of this technology have recently been used for creating quite a few, and very impressive, animated pictures (such as Shrek", or Nemo"). Imagine you have to realize a ray-tracer application. At the core of such an application is a data structure, which maintains and represents the scene graph or the world". Objects can be very simple objects, which have a geometrically defined shape and a typically algorithmically defined material, but they can also be arbitrarily complex compositions of other objects. The scene graph is then repeatedly traversed to check for intersections with various optical rays.

(a) Design a class structure, which can represent a scene graph. Which design pattern is applicable? (b) It is often useful to be able to transform existing objects in a scene graph, for example by moving, scaling or rotating them. This should be possible for simple and complex objects alike. Enhance the class structure from the previous subtask to enable transformation of objects. Which design pattern do you use? (c) When transforming an object it is typical to construct the transformation from the basic transformation (scaling, rotation, and translation) by putting them in a sequence of transformation operations. Extend the class structure to represent such sequences of transformations. Discuss different solutions. (d) When tracing complex objects it is often worthwhile to first check whether the ray will ever intersect their bounding box (i.e., the smallest box completely enclosing the object). Enhance the class structure to add this functionality. What design pattern could you use? Are there other ways of doing it? 9 Drinking habits (5 points) Consider the following inheritance hierarchy. Person Employee Student Professor PhD student Each Person provides a method drink, which encapsulates the drinking behavior of the person. Task: Add runtime tracing of drinking behavior. You should be able to switch tracing on or off for any object in the hierarchy at runtime. If tracing is on, the system logs when a person starts and when it stops drinking. Which design pattern could you use? What does your solution look like? 10 Flight booking (10 points) Suppose you should design an application, which enables clients to book the cheapest flight to a destination of their choice from a number of providers. (a) Assume, every provider is known in advance, and implements an interface IFlightProvider, which provides operations for querying for a connection, and for

booking a flight. In this application you will need a way to enable clients to interface to these providers and book the cheapest flight on offer for the destination and date they are interested in. Flight providers should require (and receive) no knowledge on other flight providers known to the system. Which design pattern could you use? (b) Many airlines offer on-line booking services as web services. How can you incorporate such an airline as a flight provider in the system above? 11 Generic event-driven simulator (15 points) Consider a generic event-driven simulator, i.e. a simulator skeleton that may simulate a wide range of systems. The simulator contains a queue of events and a variable indicating the simulated time. Each event has a time stamp that indicates the time at which the event will occur. The queue contains events, which are sorted in the ascending order of the time at which the events occur. The generic event-driven simulator executes the following infinite loop provided by the simulate method of class GenericSimulator: abstract class GenericSimulator protected State newstate, oldstate; protected double simulatedtime; protected EventQueue eventqueue; protected Event currentevent; public abstract State consequences(state oldstate, Event event); public abstract void actions(state newstate, State oldstate); public void simulate() while (true) simulatedtime = eventqueue.top().time; do currentevent = eventqueue.pop().event; newstate = consequences(oldstate, currentevent); actions(newstate, oldstate); oldstate = newstate; while (simulatedtime <= eventqueue.top().time); (a) The design of the generic event-driven simulator is based (partly) on a design pattern. Which design pattern? Motivate your answer. If unsure, motivate other alternatives that you consider. (b) The GenericSimulator is given above. Why are some methods abstract? Consider that you have to write a simulator for a specific system, let us call it WeatherSimulator. Draw the class hierarchy of this specific simulator.

(c) Could you use any of the Abstract Factory or Factory Method design patterns in order to generate system-specific events? Motivate your answer. (d) How would you implement different specific simulators using the Strategy design pattern? Consider changing the given code. Draw the class diagram of the improved system.