CS 3371 - March 20, 2000

  1. Suppose that class Derived is a subclass of class Base, and that method foo is defined in both Base and in Derived. Given this definition of the preconditions and postconditions of foo in Base:

       int foo(n: int)
       // pre: n > 0
       // post: result > log n


    which of the following definitions of foo in Derived are valid? Why or why not?

    1. int foo(n: int)
      // pre: n > 0
      // post: result > n

    2. int foo(n: int)
      // pre: n != -5
      // post: result > 0

    3. int foo(n: int)
      // pre: n > 1
      // post: result == n^2

  2. As Stevens explains in the technical note on p. 62, UML differentiates between dynamic and static associations. Which type better captures the notion of coupling among classes?

  3. Suppose that we have a List class that we want to use in developing a Queue class. Should we use inheritance, aggregation, or composition to implement the relationship between Queue and List?

  4. Consider classes Account and Customer. When would aggregation be an appropriate relationship between them, and when would composition be more appropriate?

  5. Suppose that a Person can be associated with many Banks, but that given a Bank and an account number, there is at most one Person with that account number at that Bank. Using the notation shown in figure 6.7 on page 79, draw a qualified association between Person and Bank to show that constraint.

  6. How could we eliminate the constraint expressed in figure 6.11 by introducing another class?

  7. Consider the problem of modeling the relationship between a student, a class, and the student's grade in the class. Figures 6.12 and 6.13 on pages 84 and 85 show two diagrams that represent the association. What are the pros and cons of each? How would we change the class structure if a student could take the same class twice and so could get two different grades for it?

  8. In figure 6.14 on page 87, what do each of these mean?

    1. The stereotype <<interface>>.
    2. The dashed arrow with the triangular head.
    3. The dashed arrow with the v-shaped head and stereotype <<use>>.
    4. The dashed arrow with the v-shaped head and no stereotype.
    5. The "lollipop" labeled Stringifiable.

  9. C++ supports parameterized classes (i.e., class templates), but Java does not. How can we design Java classes to get some of the same code reuse benefits that parameterization offers?