MSc-IT Study Material
January 2011 Edition

Computer Science Department, University of Cape Town
| MIT Notes Home | Edition Home |

Review

Questions

Review Question 1

How many of the different methods of managing heavy loads have been used in constructing the Firth of Forth Bridge?

A discussion of this question can be found at the end of this chapter.

Review Question 2

What is the principal difference between the job of a software engineer and those of architects and civil engineers?

A discussion of this question can be found at the end of this chapter.

Review Question 3

Explain the role of design patterns in object-oriented software development.

A discussion of this question can be found at the end of this chapter.

Review Question 4

Place each of the following patterns in the category it belongs to according to the gang of four:

Patterns: Observer, Model-View-Controlled, Abstract Factory, Composite:

Category: Creational, Structural, Behavioural.

A discussion of this question can be found at the end of this chapter.

Review Question 5

What are the four essential elements of a design pattern catalogue entry?

A discussion of this question can be found at the end of this chapter.

Review Question 6

What is meant by granularity?

A discussion of this question can be found at the end of this chapter.

Review Question 7

Give examples of white-box reuse and black-box reuse from the pattern examples.

A discussion of this question can be found at the end of this chapter.

Review Question 8

Compile ECG.java, TheObserver.java and TestPattern.java, then execute the TestPattern program.

  1. Create a new directory in which to store the files. You may call the directory Activity1.

  2. Copy all three files ECG.java, TheObservers.java and TestPattern.java

  3. Compile the three files using the JDK command javac

  4. Once the compilation is successful you should be able to execute the TestPattern application using the command java Testpattern

Does the program output the messages in the order you have expected?

A discussion of this question can be found at the end of this chapter.

Review Question 9

Design a solution using the Observer pattern for the operation of dispensing cash by an ATM machine. When a bank customer withdraws money from an ATM (Automatic Teller Machine), before the cash is dispensed it is necessary to determine whether there are sufficient funds. If there are, then it is necessary to instruct the machine to dispense the cash, to debit the customer's account and to log the transaction for auditing purposes.

How would you use the Observer pattern to design a solution to this problem?

A discussion of this question can be found at the end of this chapter.

Review Question 10

Draw a diagram to represent the design pattern of a solution to the ATM operation of dispensing cash using the Observer pattern. You may use a CASE tool for the class diagram and include the outline of the methods, data and messages required to make the pattern work. It would be useful if you put the project in which the class diagram will be placed into a new directory.

A discussion of this question can be found at the end of this chapter.

Review Question 11

The code you are expected to write will be a skeleton for the Observer pattern with messages instead of complex code to implement the operations. Compile the three parts of the program in the correct order. The Observable class, then the Observer and last the program. You may use any version of Java for this exercise. Follow the instructions similar to the ones given for Activity 1. It would be useful to place all of your files for this exercise in a new directory.

A discussion of this question can be found at the end of this chapter.

Answers

Discussion of Review Question 1

The Firth of Forth bridge uses three patterns which can be directly seen. These are:

  • girders with cross-members,

  • arches in a catenary shape,

  • decreasing the span.

In addition some suspension support is provided 'from above' but this is not strictly a catenary shape.

Discussion of Review Question 2

The main difference is that software engineers do not have the opportunity to see their and other people's designs implemented visually.

Discussion of Review Question 3

Your answer is expected to include some of the following:

Serve as exemplars to programmers, designers and architects, which they can quickly adapt for use in their projects.

Emphasise solutions: discovering patterns that have been used before rather than inventing them.

Represent codified, distilled wisdom: solutions to recurring problems, if those solutions have well understood properties.

Allow programmers and designers to program and design using bigger chunks; this also eases those aspects that involve understanding an architecture; architectural reviews. Reverse engineering, maintenance and system restructuring.

Aid in communicating among designers, between designers and programmers, and between a project's team members and its non-technical members.

Identify and name abstract, common themes in object-oriented design, themes that have known qualify properties.

Form a documented, reusable base of experience, which would otherwise be learnt only through an informal oral tradition or through trial and error.

Provide a target for reorganisation of software because a designer can attempt to map parts of an existing system to a set of patterns. If this mapping can be done, the complexity of the resulting reorganised system will be less than the original version.

Discussion of Review Question 4

Behavioural: Observer, M-V-C

Creational: Abstract Factory

Structural: Proxy, Composite

Discussion of Review Question 5

  • The pattern name which identifies a commonly agreed meaning and represents part of the design vocabulary.

  • The problem or family of problems and conditions in which it may be applied.

  • The solution which is a general description of participating classes/objects and interfaces their roles and collaborations.

  • The consequences - each pattern highlights some aspect of the system, and not others so it is useful to be able to analyse benefits and restrictions.

Discussion of Review Question 6

Granularity usually refers to the size of the components you deal with. In this context it could be from patterns that specify how a single object may be created, to patterns that will specify the structure of a whole application.

Discussion of Review Question 7

For example, in the Observer pattern:

Concrete Observer is an example of black-box reuse because all the Concrete observer needs to do is to implement the update() method.

The Concrete Subject is an example to white-box reuse, because it needs to know the details of its super class Observable.

The Concrete Factory of the Abstract Factory pattern is an example of white box reuse. The way in which the Client Application uses the Abstract Factory pattern is an example of black box reuse. Etc.

Discussion of Review Question 8

Compare this example with the Observer catalogue entry description, and follow the instructions on how to use a design pattern before going on to do the next exercise.

Discussion of Review Question 9

This exercise will help you test your understanding of the Observer pattern. You are expected to base your answer on the given examples – to literally use the pattern. Using the CASE tool will help you produce the documentation of your design in the standard format.

Discussion of Review Question 10

The purpose of this exercise is to use the Observer class and Observable interface from java.util and to test some of the methods from the lecture notes. This will consolidate your understanding of the use of this design pattern.

Discussion of Review Question 11

Writing portable software, and implementing dynamic binding of objects in a distributed environment for which Java was designed requires developers to be aware of the different platforms, and be able to make sure applications take advantage of the facilities in the language that make it possible to port.