ECE450 - Software Engineering II

Winter 2007

Sample Final Exam Questions

In the same spirit as the sample midterm questions, these examples should give you a feel for the type of questions you may expect in the final. Make sure to read the midterm examples again, as they're still relevant for the final.

Question 1

Explain what the "favour composition over inheritance" principle means. Why is it important? Name two design patterns that apply it, and explain why.

Hints for an answer: This question is both about high-level design concerns and particular design patterns. Make sure you understand the design principles we've been discussing in lectures. In particular, composition over inheritance means that it is better to add behavior to an application by composing structures of objects than by subclassing an already existing class. A subclassing strategy may easily lead to subclass explosion; a composition strategy is much more versatile. Among the patterns that apply the principle we have the Decorator and Strategy patterns. Decorator adds behavior by wrapping objects (composing structures of recursive wrapping), Strategy offers the possibility of connecting classes with particular strategies to execute an algorithm.

Question 2

What design patterns might be involved in (a) the design of a module with a class that defines the key steps of an operation, but lets the user configure the details of each step from a number of alternatives? (b) a tree structure that allows for a still unknown and potentially unlimited number and kind of operations to be executed in all of its members, with the execution varying depending on the type of each component of the structure?

(a) is a straightforward Template Method pattern. (b) is a Visitor running over a Composite structure.

Question 3

While designing a word processing application, you need to take a decision on how to render the format of the text (that is, how to handle the rendering of bold, italics, several font sizes, etc.). You are considering three alternatives. The first is to implement Decorator: you apply decorator wrappers to pieces of text, and the decorator takes over the rendering instructions by exploring the characteristics of lower-level decorators in the structure and aggregating them. The second is to implement State: you may keep the switch to Bold state, or Italics state, whenever you find an indication in the text, and render the words appropriately. The third is to implement Strategy: every character has a rendering strategy that it will call when being asked to render itself, and the object can pick different strategies depending on its current style. Discuss the advantages and disadvantages of each alternative, select the most appropriate one, and explain your selection.

Hints for an answer: You need to think what will each implementation do to the application as a whole, and whether they're even feasible alternatives in the first place. The second alternative, for example, is bogus: State is a terrible fit here since we're bringing it too far away from its original intent. The first and third alternatives are feasible, and have interesting implications: Decorator will cause an awkward parsing of each character's wrappers, Strategy may lead to a subclass explosion if we need to consider every combination of styles separately. The discussion of advantages and disadvantages should be expanded in more detail than what I present here. In this case, it seems Decorator is the superior alternative among the three, since even with its parsing difficulties it makes for cleaner structures than Strategy's mess.