• Keine Ergebnisse gefunden

Design Patterns & Concurrency — Lab Exercise 3

N/A
N/A
Protected

Academic year: 2022

Aktie "Design Patterns & Concurrency — Lab Exercise 3"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

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

Referenzen

ÄHNLICHE DOKUMENTE

Managing access to state, in particular to shared, mutable state (directly to member- variables of one class) with. ‣ Atomic change

According to GoF, there are two fundamental principles of reusable software design (that also underly most if not all patterns):2. 1 st Principle of

public final class PhoneNumber implements Product { private final short areaCode;. private final

@ThreadSafe //assuming that finder instance is threadsafe public class MovieLister implements MovieFinderInjector { private MovieFinder finder;.. public

increased runtime, because client has to compute or access stored extrinsic state information, and pass it into flyweight objects. ‣ Memory saving

public static final class Memento { private final int state;. private Memento(int state) { this.state

‣ The class TCPConnection maintains a state object that represents the current state of the TCP connection.. ‣ The class TCPConnection delegates all state-specific requests

I Similar structures, in both cases indirect access to actual object via upstream object. I in both cases, upstream object maintains reference to actual object (subject) and