2006 Exam answers

From CSSEMediaWiki
Revision as of 07:23, 7 October 2008 by Elliot Fisher (Talk | contribs)
Jump to: navigation, search

Contents

Question 1

[4 marks for whole question] Provide a name (and if possible a wiki or web page reference) for each idea (a)-(d):

  1. [1 mark] An approach for executing parse trees.
    Answer:
  2. [1 mark] It is better to use abstract classes than concrete ones.
    Answer: Program to the interface not the implementation
  3. [1 mark] Design documentation is essential.
    Answer:
  4. [1 mark] A pattern containing a class called Quantity.
    Answer:

Question 2

[28 marks for whole question] For each of the following descriptions (a) – (g):

  • [1 mark each] Name a maxim (or pattern, code smell, etc) that captures the idea.
  • [1 mark each] Explain the rationale for this maxim (i.e. why the maxim exists).
  • [2 marks each] Comment on the validity and value of this maxim.
  1. [4 marks] Domain model objects should not access user interface objects.
    Answer: Presentation separation idiom
  2. [4 marks] A class should not access its subclasses.
    Answer: Dependency inversion principle
  3. [4 marks] If a class is unlikely to change, it should be abstract.
    Answer: Stable abstractions principle
  4. [4 marks] Don’t initialise attributes in constructors; instead, initialise them the first time a getter is called.
    Answer: Use lazy initialization pattern
  5. [4 marks] Structure code so that a foo() method in some object calls foo()methods in other objects.
    Answer: Recursion introduction? Law of Demeter?
  6. [4 marks] A maxim violated by the Observer pattern.
    Answer: Tell, don't ask
  7. [4 marks] Don’t write getters that return fields that can be changed.
    Answer:

Question 3

[5 marks] If you could nominate one person to receive a lifetime achievement award for services to OO design, who would you choose, and why?

Answer:

Question 4

[5 marks] Some designers suggest that it is a good idea to always declare separate interfaces from implementations, so that no class ever uses an implementation class directly; instead it uses only abstract interfaces. Is this a good idea? Justify your answer.

Answer:

Question 5

[23 marks] See Frogs second design.

Question 6

[10 marks] What conflicts or differences of opinion can be detected between the ideas of ArthurRiel1996 and KenAuer1995? Do the underlying philosophies of the authors differ? Justify your answers, and where possible, support them with evidence from the papers.

Answer:

Question 7

[25 marks] On your first day in a new software engineering job, you’re shown the Account class (Figure 3), which represents foreign exchange accounts that hold money in a particular currency. It records all exchanges of money from one Account to another, using the current exchange rate to calculate the result. Your manager says:

"It is pretty much complete – it was designed by a top consultant – but we need you to extend it to cope with exchange rates that vary over time. We need to retain all info, so we should be able to find out what exchange rate was used for any exchange, even if it happened a long time ago. We also need it to handle more than 100 Accounts."

Criticise the design (and implementation) and suggest how it should be improved in order to support the requested features and to fix problems the manager was unaware of. Where possible, support your arguments and explain your design with maxims, patterns, refactorings, etc, and provide UML diagrams. If you need to make any assumptions about requirements, make a note of what you assumed and why.

public class Account {
  ...
}
Answer:
Personal tools