Exam in TDDB84: Design Patterns,

Similar documents
SDC Design patterns GoF

UNIT I Introduction to Design Patterns

TDDB84: Lecture 09. SOLID, Language design, Summary. fredag 11 oktober 13

Design Patterns Reid Holmes

Software Engineering

EINDHOVEN UNIVERSITY OF TECHNOLOGY

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

DESIGN PATTERN - INTERVIEW QUESTIONS

UNIT I Introduction to Design Patterns

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

Object-Oriented Oriented Programming

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

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

The GoF Design Patterns Reference

CSE 70 Final Exam Fall 2009

An Introduction to Patterns

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

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

Design Pattern and Software Architecture: IV. Design Pattern

Object-oriented Software Design Patterns

Topics in Object-Oriented Design Patterns

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

INSTITUTE OF AERONAUTICAL ENGINEERING

A4 Explain how the Visitor design pattern works (4 marks)

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

The Design Patterns Matrix From Analysis to Implementation

Idioms for Building Software Frameworks in AspectJ

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

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

Design Patterns Revisited

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

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

Summary of the course lectures

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

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

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

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

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

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

Introduction to Software Engineering: Object Design I Reuse & Patterns

Chapter 5 Object-Oriented Programming

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

May Comp-B 11, Advanced Software Design. 3 hours duration

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

LABORATORY 1 REVISION

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

Design Patterns: Structural and Behavioural

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

Design patterns. Jef De Smedt Beta VZW

A Reconnaissance on Design Patterns

NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

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

Object-Oriented Concepts and Design Principles

Object-Oriented Design

JAVA MOCK TEST JAVA MOCK TEST II

What is Design Patterns?

Topics. Software Process. Agile. Requirements. Basic Design. Modular Design. Design Patterns. Testing. Quality. Refactoring.

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

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

SWEN425 DESIGN PATTERNS

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

What are the characteristics of Object Oriented programming language?

Tuesday, October 4. Announcements

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Inheritance (Chapter 7)

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

TDDB84. Lecture 2. fredag 6 september 13

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Software Development Project. Kazi Masudul Alam

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism


Object Oriented Programming. Java-Lecture 11 Polymorphism

INSTRUCTIONS TO CANDIDATES

Information systems modelling UML and service description languages

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

Unit Wise Questions. Unit-1 Concepts

Using Design Patterns in Java Application Development

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

CSC207H: Software Design Lecture 6

Chapter 6 Introduction to Defining Classes

CSE 331 Summer 2017 Final Exam. The exam is closed book and closed electronics. One page of notes is allowed.

COURSE 2 DESIGN PATTERNS

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

Object Oriented Programming: Based on slides from Skrien Chapter 2

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

Creational Design Patterns

A few important patterns and their connections

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

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

Design Patterns Reid Holmes

Foundations of Software Engineering Design Patterns -- Introduction

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

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

Object Orientated Analysis and Design. Benjamin Kenwright

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

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

COP 3330 Final Exam Review

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Transcription:

Exam in TDDB84: Design Patterns, 2014-10-24 14-18 Information Observe the following, or risk subtraction of points: 1) Write only the answer to one task on one sheet. Use only the front side of the sheets (answers to several subtasks can be on one page). 2) Sort the solution sheets according to the task number. 3) Answers may be in English or Swedish. 4) Your answers should clearly show solution methods, reasons, and arguments. If you have to a make an assumption about a question, write down the assumptions you make. Also, be specific in your answers. 5) Only a dictionary is allowed during the exam. Grading To pass the exam you have to do at least 20 points from 40 possible. Grades are based on the following grade table: Points Grade 0-19 U 20-27 3 28-34 4 35-40 5

Task 1: Design Patterns and SOLID: Definitions, use and explanations (10 points / 2 point for each question) A. Finish the following sentence: The Command design pattern a) encapsulates user interactions Yes, this is the most common use of the Command pattern. b) consists of Director, Client and Command objects collaborating No, there is no Director in the Command pattern c) implements a history No, this is not an inherent feature of the Command pattern, but possible by using a Memento together with the Command pattern. Select the most appropriate end of the sentence and justify. B. Violations of the Dependency Inversion Principle can be recognized by: a) Classes with many public methods that return many different types of objects. No, not related to dependency management b) Classes that are difficult to run automated tests on.yes, hard-wired dependencies typically lead to issues in testing c) Public 0-argument constructors that use factory methods to initialize field values. Yes, this is a typical anti-pattern that leads to b). Select the alternative(s) that apply and justify your answer. C. Select the appropriate design pattern for the following tasks: a) Translating XML structures into object graphs. Builder, as the traversal of XML is the job of a Director, and a Concrete Builder may be used to create the object graph b) Creating different applications runtime environments for testing. Abstract Factory, as the related sets of objects needed for testing need to be specified by a common Concrete Factory. c) Dynamically attach logging behavior to objects at runtime. Decorator, as it provides the same interface as the original object and can be substituted for the original object at runtime. Justify your answer. D. Finish the following sentence: The Liskov Substitution Principle means that a) Subclasses should have only as many public methods as superclasses do. No, not necessary. b) Subclasses methods need to return the exact same values for all arguments as their overridden counterparts do. Not necessary either, depending on the requirements of the contract between classes. For instance, it is quite alright to override methods in class Object and provide custom comparisons, hash values or string representations in Java. c) Subclasses cannot ignore to properly implement methods declared in superclasses. This is the most appropriate answer, if we interpret properly as that clients should be able to expect the same things from the subclass as the superclass. Select the most appropriate end of the sentence and justify. E. The Composite design pattern: a) traverses a composite structure. No, that is the job of an Iterator b) defines both inheritance and composition relationships between two classes. Yes, this is a defining feature.

c) defines a set of methods that can be applied to tree structures. No, this is a feature of the Visitor pattern. A Composite does not necessary define a set of methods applicable to tree structures, but ensures that leaves and non-leaves are treated in a uniform manner, so clients to not need to care about the structure of a composite object. Select the most appropriate alternative(s) and justify.

Task 2: Design Patterns and Software Qualities (10 p) A. (2p)Security is an important quality of software. Give an example of a design pattern that can prevent illegal access to sensitive data and explain how it works. A proxy B. (4p) One of the claims made about the effects of design patterns is that they improve software maintainability. In the following subquestions feel free to draw UML diagrams and to write pseudocode to help you illustrate your answer. a) Describe a piece of code that is currently difficult to further develop or extend. Justify why the example creates problems related to maintainability by clearly explaining what functionality your example could be extended with. b) Apply one or more software design patterns and describe the consequences of implementing them. Explain why this is an improvement with respect to maintainability. That is, give an example of an extension to the original example and an example refactored to implement a design pattern, and compare the two. C. (2p) Name and describe a metric for software quality. MOOD would be ok to describe in full, or any of the components of MOOD. D. (2p) Name and briefly explain two effects that have been claimed about the effectiveness of design patterns in the literature. 1. Using patterns improve programmer productivity and program quality. 2. Novices can increase their design skills significantly by studying and applying patterns. 3. Patterns encourage best practices, even for experienced designers. 4. Design patterns improve communication, both among developers and from developers to maintainers.

Task 3: Design Patterns, Programming languages and programming paradigms (10 p) A. (4p) Design patterns may be categorized in terms of how far they are from becoming actual language features in order to learn something about them. Describe how the classes cliché and cadet are defined, and give examples in Java of each, and describe two design pattern in Java that are idioms in another language. Describe how features of the other language affect the implementation of the design pattern. A cliché is a trivial feature such as Template Method, which is simply polymorphism. A cadet is a candidate for a language feature, but too domain-specific, too vague, or else lacking the abstraction level that would warrant their inclusion as language features. Examples are Adapter, Bridge, Chain of Responsibility. The idiomatic implementation of a Proxy in Ruby relies on the dynamic dispatching of method calls through the use of method_missing. The idiomatic implementation in CLOS (Common Lisp Object System) of a Visitor relies on the use of multi-methods. B. (6p) Use the code examples below to discuss the effects of replacing the Observer pattern with the Reactive Programming paradigm on semantic distance, abstraction level and separation of concerns. Relate to specific features of the code examples in your answer. In example 1, the behavior the user wants is to trace and draw a path as long as the mouse button is pressed. The code does not read like that, however, due to the inversion of control. In example 2, the path generates mouse movement data during the time interval when the mouse button is pressed and encapsulates path generation in a way that corresponds to what it means for something to be a path, thus decreasing the semantic distance between the code and the concept of a path. In example 1, the only events that can be observed are the primitive mouse events, whereas in example 2, we can observe changes to the path and introduce new such abstractions at will, by creating new signals. In example 1, all logic related to path management, drawing, and the manipulation of observers is encapsulated in observers, whereas in example 2, path management is internal to the path signal itself, and drawing is performed whenever changes are emitted, thus separating those concerns. Example 1: val path: Path = null val moveobserver = { (event: MouseEvent) => path.lineto(event.position) draw(path) control.addmousedownobserver { event => path = new Path(event.position) control.addmousemoveobserver(moveobserver) control.addmouseupobserver { event => control.removemousemoveobserver(moveobserver)

path.close() draw(path) Example 2: val path: Signal[Path] = Val(new Path) once { self => import self._ val down = next(mousedown) // Waits for a mousedown event emit(previous.moveto(down.position)) // Generates a new signal value loopuntil(mouseup) { val m = next(mousemove) // Waits for a mousemove event emit(previous.lineto(m.position)) // Generates a new signal value emit(previous.close) // Generates a new signal value observe(path)(draw) // Connects the operation 'draw' to the path values // emitted by the signal

Task 4: Design Patterns and application frameworks (10p) A. (4p) The literature describes two types of application frameworks: black-box frameworks and white-box frameworks. Explain the differences in terms of how systems are built using them, design patterns that they make use of, and properties applications built using them will have. White-box frameworks use inheritance and design patterns such as Template Method. They tend to lead to tightly coupled systems as developers must extend base classes in the framework to use them. Black-box frameworks use object composition and delegation, and design patterns such as Strategy, Chain of Responsibility and Decorator, and tend to result in systems that are not as tightly coupled to specific base classes, only to interfaces provided by the black-box framework. B. (6p) Describe a design property that distinguishes application frameworks from libraries. Also, describe at least three design patterns that lead to systems with this property, and justify your answer. Inversion of control, meaning that the framework controls the execution of code in the application, and invokes user-defined methods and uses objects that the developer has supplied for specifying behaviour at specific points during the lifetime of the application. Examples of design patterns that imply inversion of control are Observer (individual observer objects do not control the invocation of their methods, but attach themselves to an Observable), State (individual states register themselves in a state machine, but are unaware of the events that trigger their use), and Visitor (visitor objects do not control how they are invoked, but are used by some traversal mechanism that can call suitable methods whenever appropriate).