SDA SE Wiki

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

User Tools

Site Tools


Assignment 9: Specifying Interfaces

Task 03-05 are optional. Nevertheless we recommend that you solve at least one of them.
Task 02 and Task 03 are the OCL tasks from the exams in 2010 and 2011.

Task 01: java.util.Queue, OCL

3 points

Consider the Queue interface in the java.util package. Write pre- and postconditions in OCL for the following operations:

  1. E remove(): Retrieves and removes the head of this queue
  2. boolean offer(E o): Inserts the specified element into this queue if possible
  3. E peek(): Retrieves but does not remove the head of this queue, returning null if this queue is empty

Task 02: Online Shop, OCL

3 points

Have a look at this diagram:

Online Shop Domain Model

Strengthen the given domain model by formulating OCL constraints which specify the following:

  1. Precondition: The arguments username and password (pw) of register method of OnlineShop class must not be null.
  2. Invariant: A premium customer must have more than 100 orders.
  3. Invariant: For each customer not more than one order is allowed to be active at the same time.

Task 03: House Automation, OCL (Optional)

3 points

The diagram below illustrates a house automation system controlling blinds. Blinds automatically turned down between 20 and 8 o'clock. In case it is dark outside the blinds are turned down, too. This is achieved by calling updateBlinds(..) every hour. The current hour (0-23) is passed as an argument to the method.

House Automation Domain Model

Strengthen the given domain model by formulating OCL constraints for the HouseAutomation.updateBlinds(..) method:

  1. Precondition: The parameter hour of the updateBlinds(..) method must be larger or equal to zero and smaller than 24.
  2. Postcondition: During hours that are smaller than 8 or larger than 20 or in case that the light sensor measures values below 50 lumen the blinds are down.

Task 04: Liskov Substitution Principle and Method Signatures (Optional)

3 points
  • Assume C is a subtype of B and B is a subtype of A (e.g. C extends B and B implements A). Compare the strength of the conditions “x is of type A”, “x is of type B”, “x is of type C”!
  • Assume now that T is a subtype of S. We expect T to fulfill all contracts of S, especially the methods in T should “demand no more” and “promise no less”.
  • In the occult OO language that we are discussing this is the only restriction on the types of parameters and return types.
  • Given that S has a method B m(B x) and m is overriden in T. Which of the following signatures would be allowed for m in T:
    1. A m(B x)
    2. C m(B x)
    3. B m(A x)
    4. B m(C x)
    5. A m(C x)
    6. C m(A x)
  • Maybe it helps you to meditate about the following code: S s = new T(); B input = new B(); B output = s.m(input);
  • Explain how this could improve the Builder Pattern (Slide 50) a bit.

Task 05: Proxy Pattern (Optional)

3 points
  1. Explain shortly the motivation and the functionality of the proxy pattern. Which are the participating roles of the proxy pattern? Which responsibilities do they have? Which operations are necessary?
  2. Present one example for each proxy variant, discuss the differences and present the motivation behind each one.
  3. What is the difference between the proxy and adapter pattern?
teaching/lectures/oosc/2012/assignment_9.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024