Design Patterns & Concurrency — Lab Exercise 3
Prof. Dr. Oliver Haase
Problem 1
The fileexercise3.zipcontains a few interfaces and classes that constitute a simple client server application. Your task is to integrate the different creational patterns into this sample application. Please proceed as follows:
1. Familiarize yourself with the sample application by reading the source code, and by running TcpServerand TcpClient.
2. Draw a UML class diagram that shows the implements, extends, and uses relati- onship between the classes and interfaces in theexercise3 package.
3. Replace alluses dependencies of a class Aon a class B with dependencies ofA on an interfaceIthatB implements. Do this using the following creational patterns:
a) Factory method
b) Abstract factory, passed in explicitly
c) Abstract factory, passed in through dependency injection
4. Try to use the prototype pattern to decouple the classes. What obstacles do you face? Can they be overcome? Justify your answer.
5. Starting from the original code, modify the two classesTcpServerand TcpClient to make them singletons. Use both the ‘usual’ implementation as classes with static getInstancemethods, and the ‘modern Java idiom’ implementation as enums.
6. Starting from the abstract factory solution in 3b above, modify the concrete fac- tory classes to make them singletons. Again, use both the ‘usual’ implementation as classes with staticgetInstancemethods, and the ‘modern Java idiom’ imple- mentation as enums.
Good luck & have fun!
1