Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

Assignment 10: Design Pattern and Specifying Interfaces

Due at Friday, July 2nd, 23:59

Task 36: Mediator Pattern and Abstractness-Stability-Diagram

4 points

In this task you will learn how to use the Abstractness-Stability-Diagram to decide whether a certain design pattern is appropriate or not. As the pattern wasn't covered in the lecture we quickly introduce it here:

The Mediator Pattern

Class Diagram for the Mediator Pattern
  • The Mediator pattern is a behavioural pattern.
  • Interaction between different colleague objects gets encapsulated in a mediator object.
  • The Mediator defines all possible interactions between the colleagues.
  • A ConcreteMediator then implements these interactions between the ConcreteColleagues.
  • If a ConcreteCollegue wants to communicate with another ConcreteCollegue they will not communicate directly, but through the ConcreteMediator.
  • So there is no coupling in between the ConcreteColleagues but only between the ConcreteColleagues and the ConcreteMediator.

Your Task

  1. Draw an Abstractness-Stability-Diagram1) for the mediator pattern.
    • Is the position of every class unambiguous?
    • Which assumptions do you have to make?
  2. Find an example where the usage of the mediator pattern is useful.
    • Draw a class diagram that shows which part of your example corresponds to the classes of the pattern shown above.

Task 37: Locating Design Pattern in Code

6 points

In the lecture you became familiar with Creational Pattern (Abstract Factory, Builder), Structural Pattern (Adapter, Bridge, Composite, Facade, Proxy), Behavioral Pattern (Command, Observer, Strategy), and the Architectural Pattern “Model View Controller”. Knowing design pattern is essential for being productive in Object Oriented Software Construction. In addition they are not only useful for the construction of software, but as well for reading and understanding it.

Prepare the software you are about to study:

  • Create a Java project “JHotDraw52” in Eclipse.
  • Open the properties of the project and set the JDK Compliance (see Java Compiler) to 1.4
  • Use “Import” > “Archive File” to import the whole content of the zip file into your project.
  • Right click on the “sources” folder in your project and select “Build Path” > “Use as Source Folder”

Your task is to find three design pattern in the source code (there are more!) and be ready to explain them. Write a short text describing where to find the design pattern in the code and how it works. For each design pattern you should at least describe

  • which type (class or interface) is playing which role in the design pattern (e.g. “CompositeFigure” is playing the role of a “Composite”) and
  • three to five sentences about the collaboration between the roles as found in this source code.

Write it in your own words! Don't copy from the thousand resources you can find on the web about JHotDraw. Of course you can read them, but don't copy them. You even find explanations in the project itself the pattlets folder.

So for e.g. the Composite Pattern we would like to know: Which class is the Composite (See above)? Which class plays the Component role? How many classes are playing the Leaf role? Which? How does the Composite implement most of its operations? Does the rest of the code distinguish between Composites and Leaves? If “yes”: How? If “no”: Why?

Task 38: OCL

5 points

Lets assume the bike rental outlets should also support motorbike renting. We updated the analysis model accordingly, here is an excerpt:


The class Bikes is a list that only contains bikes. It is used to present vehicles rentable by all users.

a) Write the two pre-conditions with OCL. Hint: The boolean function oclIsTypeOf(TypeName) checks if an instance is of type TypeName or not. Do the constraints follow contract inheritance? Write a Java sample project (at least a snippet) to illustrate the problem.

b) Lets assume you want to use the Vehicles class for all logged-in users. So you restrict the use of the Vehicles::add(Vehicle) method with the following precondition: “if the vehicle is a motor bike the user must be older than 18 years and own a drivers license”

Write the constraint as an OCL constraint.

See design pattern slides.
The whole article is of course helpful to understand JHotDraw:
teaching/lectures/oosc/2010/assignment_10.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024