FHTW Berlin Medieninformatik

FHTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
SE: Software Engineering
Summer Term 2008

Exercise 6 : Design Patterns

Download Bruce Eckel's book "Thinking in Patterns" and unpack it on your desktop. We will be reading bits and pieces of this and doing some exercises.

0. Read the Introduction and the Pattern Concept chapters before coming to lab!

1. Read about the Singleton Pattern. Type in the program SingletonPattern.java to Eclipse and get it to run. Write a paragraph explaining how this really works. SingletonPattern.java always creates an object, even if it's never used. Modify this program to use lazy initialization, so the singleton object is only created the first time that it is needed.

2. Read the chapter "Object decoupling" with the patterns Proxy, State, and Interators. Using the State pattern, make a class in Java called UnpredictablePerson which changes the kind of response to its hello( ) method depending on what kind of Mood it's in. Add an additional kind of Mood called Prozac and any other moods you find appropriate.

3. The bored may play with the Object Pool solution and try and return the objects to the pool automatically after a certain amount of time.

As always, your exercise should be submitted with some observations on the process, some reflection on what you achieved, and the time you needed to complete the task.


Copyright 2006, 2007, 2008. Prof. Dr. Debora Weber-Wulff       All rights reserved.
Questions or comments: <weberwu@fhtw-berlin.de>