0% found this document useful (0 votes)
43 views7 pages

Question Paper 2007

This document contains exam questions related to software architecture and design patterns. It includes questions about inheritance vs composition, the decorator pattern, the adapter pattern, design patterns like prototype and strategies for designing object-oriented frameworks. It also contains sample code implementing the decorator pattern and class diagrams for the adapter and prototype patterns.

Uploaded by

Rohit Kshirsagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views7 pages

Question Paper 2007

This document contains exam questions related to software architecture and design patterns. It includes questions about inheritance vs composition, the decorator pattern, the adapter pattern, design patterns like prototype and strategies for designing object-oriented frameworks. It also contains sample code implementing the decorator pattern and class diagrams for the adapter and prototype patterns.

Uploaded by

Rohit Kshirsagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Department of Computer and Information Sciences 52 440 Software Architecture May 2007 Attempt TWO Questions (The allocation

of marks to parts of questions is given as a guideline and may not be adhered to rigidly.) In accordance with Regulation 4.3.5, the use of calculators is not permitted. (2 hours)

1. (a)

(i)

In object-oriented software development a graphical window could be constructed from a Java JFrame using either inheritance or composition. Using diagrams, explain how this is achieved using both of these mechanisms. With reference to the JFrame example, identify the relative strengths and weaknesses of inheritance and composition in developing object-oriented systems.

(ii)

(iii) Hence, explain the object-oriented guideline Favour object composition over class inheritance. (8 marks)

PLEASE TURN OVER

52 440

Page 1 of 7

(b)

(i) (ii)

State the intent of the Decorator design pattern. The Java code in Figure 1 (at the end of the examination paper on pages 6 and 7) is an example of how the Decorator design pattern can be used to add vertical and horizontal scrollbars to a window. Explain how the Decorator pattern makes use of both inheritance and composition and identify the benefits that Decorator derives from each of these.

(iii)

Given the following definition of decoratedWindow based on the code in Figure 1


Window decoratedWindow = new HorizontalScrollBarDecorator ( new VerticalScrollBarDecorator( new SimpleWindow() ) );

Use a UML sequence diagram to sketch out the sequence of messages that would result from the following method invocation
decoratedWindow.getDescription()

and hence identify the String value that would be returned as a result. (8 marks) (c) The intent of the Adapter design pattern is Convert the interface of a class into another interface clients expect The diagrams in Figure 2 show two approaches to the Adapter pattern, a Class Adapter based on multiple inheritance and an Object Adapter based on a combination of inheritance and composition.

Figure 2: Class diagrams for the Class Adapter and Object Adapter design patterns

PLEASE TURN OVER

52 440

Page 2 of 7

(i)

Explain the key differences between these two approaches to the Adapter design pattern.

(ii) Given a Stack interface as follows:


interface Stack { void push (Object o); Object pop (); Object top (); }

and the outline of a DoubleLinkedList class DList:


/* DoubleLinkedList */ class DList { public void insert (DNode pos, Object o) { ... } public void remove (DNode pos, Object o) { ... } public void insertHead (Object o) { ... } public void insertTail (Object o) { ... } public Object removeHead () { ... } public Object removeTail () { ... } public Object getHead () { ... } public Object getTail () { ... } }

Show how the Dlist class can be adapted to the Stack interface using both the Class Adapter and Object Adapter design patterns. (iii) Identify one situation where the Class Adapter would be preferred to the Object Adapter. Identify one situation where the Object Adapter would be preferred to the Class Adapter (9 marks)

PLEASE TURN OVER

52 440

Page 3 of 7

2. (a)

(i) (ii)

Distinguish between Hot Spots, Frozen Spots and Hooks in the design of object-oriented frameworks. Identify three different techniques used for designing Hot Spots in an object-oriented framework.

(iii) Using your experience of the object-oriented framework JHotDraw, provide the details of an actual example of each of these three Hot Spot techniques. (9 marks) (b) Figure 3 provides the class diagram representation of the Prototype design pattern
Client
Operation() p = prototype.Clone() prototyp

Prototype
Clone()

ConcretePrototypeA
Clone()

ConcretePrototypeB
Clone ()

Return copy of self

Return copy of self

Figure 3: Prototype class diagram

(i)

Provide the following: - A statement of the Intent of the Prototype pattern - A brief overview how it achieves its intent In an object-oriented framework such as JHotDraw the Prototype design pattern can be used to build a range of tools for creating different figures. Sketch out a UML class diagram similar to Figure 3 that shows how the Prototype design pattern can be used to achieve this. Your diagram should show classes for the different figures to be created e.g. Square and Circle, and also the Tool class. It should also identify how the Tool knows which figure it is to create. You should assume that the figure is created by a method mouseDown associated with the Tool class. Provide a brief explanation of your diagram. (8 marks)

(ii)

PLEASE TURN OVER


52 440 Page 4 of 7

(c)

(i) (ii)

Identify a design pattern that is a standard alternative to Prototype and which could be used to solve the problem described in part b(ii) above. Hence, sketch out another UML diagram which shows how this alternative design pattern would solve this problem. Provide a brief explanation your diagram.

(iii) Identify the relative strengths of these two patterns in what circumstances would you suggest the use of each instead of the other. (8 marks)

3. (a)

The keyword-in-context index system accepts an ordered set of lines, each line is an ordered set of words, and each word is an ordered set of characters. Any line may be circularly shifted by repeatedly removing the first word and appending it at the end of the line. The keyword-in-context index system outputs a listing of all circular shifts of all lines in alphabetical order. (Parnas, 1972) (i) Sketch a software architecture for the keyword-in-context index system that uses the pipe-and-filter architectural style. Briefly describe the function of each component and identify the key characteristics of the overall architecture style. Sketch a software architecture for the keyword-in-context index system that uses the implicit invocation style. Briefly describe the function of each component and identify the key characteristics of the overall architecture style.

(ii)

(iii) Compare and contrast the two architectures from parts (i) and (ii) of this question. Identify the benefits and limitations of each architecture compared to the other. (15 marks) (b) (i) (ii) Identify the key characteristics of a software component. Identify the key features of the JavaBean component model.

(iii) Identify how Meyers definition of a trusted component differs from that of a software component as defined in part (i). Identify the main features of both Meyers low road and high road to trusted components. (10 marks)

PLEASE TURN OVER

52 440

Page 5 of 7

// the Window interface interface Window { public void draw(); // draws the Window public String getDescription(); // returns a description of the Window }

// implementation of a simple Window without any scrollbars class SimpleWindow implements Window { public void draw() { // draw window } public String getDescription() { return "simple window"; } }

abstract class WindowDecorator implements Window { protected Window decoratedWindow; // the Window being decorated public WindowDecorator (Window decoratedWindow) { this.decoratedWindow = decoratedWindow; } public void draw() { decoratedWindow.draw(); } public String getDescription() { return decoratedWindow.getDescription(); } }

// the first concrete decorator which adds vertical scrollbar functionality class VerticalScrollBarDecorator extends WindowDecorator { public VerticalScrollBarDecorator (Window decoratedWindow) { super(decoratedWindow); } public void draw() { drawVerticalScrollBar(); super.draw(); } private void drawVerticalScrollBar() { // draw the vertical scrollbar } public String getDescription() { return super.getDescription() + ", including vertical scrollbars"; } }

// continued over the page

52 440

Page 6 of 7

// the second concrete decorator which adds horizontal scrollbar functionality class HorizontalScrollBarDecorator extends WindowDecorator { public HorizontalScrollBarDecorator (Window decoratedWindow) { super(decoratedWindow); } public void draw() { drawHorizontalScrollBar(); super.draw(); } private void drawHorizontalScrollBar() { // draw the horizontal scrollbar } public String getDescription() { return super.getDescription() + ", including horizontal scrollbars"; } }

Figure 1: Java code that uses the Decorator pattern to add scrollbars to a window

52 440

Page 7 of 7

You might also like