Sie sind auf Seite 1von 3

Universitt Stuttgart

Institute of Industrial Automation and Software Engineering


Prof. Dr.-Ing. Dr. h. c. P. Ghner

Exercise 2 Introduction to UML


Question 2.1 Associations between Objects

a) Develop a class diagram from the object diagram in figure 1:

Point1 Point2

x = -10 x = 10
y = 10 y = 10

Polygon1

Point3 Point4

x = -10 x = 10
y = -10 y = -10

Figure 1: Object diagram for a polygon which is a square by accident

Dont add multiplicities yet. Consider that each point has an X and a Y coordinate. How can
you express the fact that points are in an order?

b) Which number of points is at least necessary, in order to design a polygon?


Add multiplicity information to the class diagram of a), so that
1. each point object always belongs to exactly one polygon only; i. e. if there are
polygons having one or several points in common, two or more point objects are
allocated to the same position (figure 2).
2. each point object always belongs to exactly one position; i. e. if there are polygons
having one or several points in common, the same point object is associated with
two or more polygons (figure 3).

Figure 2: Two point objects Figure 3: One point object

WS 04/05 1 03 Nov 2004, Gt


Software Engineering for Real-Time Systems Exercise 2: Introduction to UML

c) Consider two triangles sharing a common side as depicted by figure 4. Draw an according
object diagram for each of the cases of point object allocation named in b).

(0, 1) (1, 1)

(-1, 0) (-1, 0) (1, 0)

Figure 4: Triangles

Question 2.2 Associations between Classes

The class diagram in figure 5 expresses the following issue about a car management system:
A person can have up to three companies as employer.
The employer IDs are equal to the company IDs the person is working for.
Cars can be owned by persons, companies or banks.
The car owner ID is equal to the ID of the person, the company or the bank owning the
car.
The purchase of a car may be associated with a car credit granted by a bank.
Unfortunately several classes contain attributes, which are actually pointers to other objects
and could be replaced by associations. It would be inconvenient to keep an object model
where pointers are hidden in class attributes.

Person Car CarCredit Company Bank

Name Owner ID Car ID Name Name


Age Car ID Type of customer Company ID Bank ID
Employer 1 ID Type of owner Account number
Employer 2 ID Model Bank ID
Employer 3 ID Year Interest rate
Person ID Account balance
Address

Figure 5: Classes with several attributes, which are actually pointers

Draw a class diagram, in which the pointers are replaced by associations. Introduce
generalizations where useful. Try to determine the multiplicities correctly.

WS 04/05 2 03 Nov 2004, Gt


Software Engineering for Real-Time Systems Exercise 2: Introduction to UML

Question 2.3 Class Diagram of a Graphic Editor

Draw a class diagram for a graphic editor, which supports the concept of grouping. Assuming
that a document has several pages every page contains the following graphic objects: text,
geometrical objects and groups. Geometrical objects are e.g. circles, ellipses, rectangles, lines
and squares. A group is simply a set of graphic objects, which can contain further groups for
its part. A group has to contain at least two graphic objects. A graphic object can be a direct
member of at most one group.

Question 2.4 Class Diagram of a Banking Software

You are a software developer working in a company which develops bank software systems.
A customer has sent the following short description of a new software system:

A person becomes a customer, if she or he opens an account. A customer can open an


arbitrary number of additional accounts. For every new customer the name (which may be
ambiguous), the address, the date, when she or he has opened the first account, are recorded.
At the opening of an account the customer has to do a first deposit. We distinguish current
accounts and savings accounts. Current accounts may be overdrawn up to a predetermined
amount. For every account an individual rate of interest on credit is fixed and for current
accounts an individual rate of interest charges, too. In addition, every account has an
unambiguous account number. About every savings account the kind of saving, e.g. fixed-
term deposit account, is stored. A customer can deposit and withdraw amounts. Furthermore
the interest on credit is credited and in case of current accounts interest charges are debited. In
order to calculate the amount of interest the date and the amount of every transaction has to be
noted down. The credit advice/direct debiting of the interest takes place annually in case of
savings accounts and quarterly for current accounts. A customer may liquidate each of his
accounts if she or she wants to. When liquidating her or his last account the person ceases
being a customer.

a) Identify the classes, attributes, operations, associations and inheritance structures in the
description above and draw a class diagram.
b) Create an object diagram assuming some data samples on your own.

WS 04/05 3 03 Nov 2004, Gt

Das könnte Ihnen auch gefallen