Assignment 08: Design Patterns 1

Release date: Wednesday, 03.06.15 - Due date: Sunday, 07.06.15, 23:59

If you like doing Task 31 and Task 32 based on Java (You can do the non-optinal part without!). You should check out:

Task 30: Inheritance

4 points

In the lecture we explained that we do not consider a good decision to let the class Stack be a subtype of List (or AbstractList). Repeat the argument and demonstrate the problem with a short program.

Task 31: Composite Pattern

8 points

The following class diagrams sketches how we could model the recipes for our baked goods:

Recipes for baked goods

The baked good has a recipe, that knows the required ingredients and is able to instruct the supplies to release the required ingredients and the oven to process the ingredients.

After a while working with this model we realized that the machine should become able to use recipes as well as components for other recipes. (Example: Bake two parts of a cake separately and the combine it.)

Change the model by introducing the composite pattern to account for recipes that have recipes as components. Give the implementation of totalIngredients() and produce(Oven, Supplies) in pseudo code or as part of our Java code. So, you either deliver a UML diagram with some pseudo code for the two methods or the pattern implemented in A08T31_CloudBakery2100StationModel.

Task 32: Observer Pattern

8 [+8] points

[If you do b) you don't need to do a) as long as you could sketch the class diagram on demand to the tutor.]

a) In our current implementation we have to press a “Refresh” button on the “Station Simulation” to retrieve the current changes. Of course it would be better, if the the table just changes as soon as new orders arrive. We suggest to realize this by having an observer pattern between the server and a controller in the station simulation. Plus, an observer pattern between this controller and the UI.

Create a class diagram plus some pseudo code to illustrate this collaboration.

b) (optional) Implement this two observer mechanisms.

Two technical tips for the observer between client and server:

  • You need to call UnicastRemoteObject.exportObject(<YourClientObserver>, 0) to make your observer instance on the client accessible to the server.
  • The call from the remote server comes not on the thread that is allowed to access the UI. You need some code like
    Display.getDefault().asyncExec(new Runnable() { public void run() { observer.onOrderPlaced(order); } });

Task 33: Mine a Pattern

8 points

One understanding of the word “pattern” is, that it describes a useful collaboration of certain classes, that occurs a few times in software systems.

Look through our code to find a pattern in the sense of a re-occuring collaboration.

If you need a suggestion, click here

If you need even more precise suggestions, click here

Describe this collaboration in a few sentences plus a class diagram.

Last modified: 2017/08/30 11:04