Docsity

UML Class Diagrams: Understanding Relationships and Multiplicity in Java - Prof. Fawzi Phi, Study notes of Computer Science

Partial preview of the text

Download UML Class Diagrams: Understanding Relationships and Multiplicity in Java - Prof. Fawzi Phi and more Study notes Computer Science in PDF only on Docsity!

UML Examples

Fawzi Emad

Chau-Wen Tseng

Department of Computer Science

University of Maryland, College Park

UML Class Diagrams

Represent the (static) structure of the system

General In Java

Name Name State Variables Behavior Methods

Relationships Between Classes

Association

Permanent, structural, “has a” Solid line (arrowhead optional)

Dependency

Temporary, “uses a” Dotted line with arrowhead

Generalization

Inheritance, “is a” Solid line with open (triangular) arrowhead

Implementation

Dotted line with open (triangular) arrowhead

OR

Association

Denotes permanent, structural relationship

State of class A contains class B

Represented by solid line (arrowhead optional)

Car and Engine classes know about each other

Multiplicity of Associations

Some relationships may be quantified

Multiplicity denotes how many objects the

source object can legitimately reference

Notation

  • ⇒ 0, 1, or more 5 ⇒ 5 exactly 5..8 ⇒ between 5 and 8, inclusive 5..* ⇒ 5 or more

Multiplicity of Associations

Many-to-one

Bank has many ATMs, ATM knows only 1 bank

One-to-many

Inventory has many items, items know 1 inventory

Association – Aggregation

Special case of association denotes a

“consists of” hierarchy

Aggregate is the parent class Components are the children class

Represented by line ending in open diamond

1

Exhaust System

Muffler Tailpipe

0..

Dependency

Denotes dependence between classes

Always directed (Class A depends on B)

Represented by dotted line with arrowhead

A depends on B

A B

Dependency Example

Class Driver depends on Class Car

Generalization

Denotes inheritance between classes

Can view as “is-a” relationship

Represented by line ending in (open) triangle

Laptop, Desktop, PDA inherit state & behavior from Computers

Implementation

Denotes class implements Java interface

Represented by dotted line ending in (open)

triangle

A implements interface B

A «B»

UML Examples

Read UML class diagram

Try to understand relationships

Examples

Pets & owners Computer disk organization Library books Banking system Home heating system Printing system

UML Example – Computer System

Try to read & understand UML diagram

UML Example – Computer System

Try to read & understand UML diagram

  • 1 CPU associated with 0 or more Controllers
  • 1-4 DiskDrives associated with 1 SCSIController
  • SCSIController is a (specialized) Controller

UML Example – Library System

Try to read & understand UML diagram

UML Example – Library System

Try to read & understand UML diagram

  • 1 or more Book associated with 1 or more Pages
  • Patron & Shelf temporarily use (depend on) Books

UML Example – Home Heating System

Try to read & understand UML diagram

UML Example – Home Heating System

  • Room has 1 Thermostat
  • Each Thermostat associated with 0 or more Heaters
  • ElectricHeater is a specialized Heater
  • AubeTH101D is a specialized Thermostat

UML Example – Printing System