Vous êtes sur la page 1sur 2

Classes

Representation of a Class

Date Date Date Date

day day
just show name Date()
month month
year getDay() year
getMonth()
getYear() Date()
show name & getDayOfWeek() getDay()
variables nextDay() getMonth()
daysBetween() getYear()
Stereotype Properties getDayOfWeek()
nextDay()
show name &
«class» Vehicle daysBetween()
methods
Date {abstract}
Class Variables & Methods show name,
optional: show optional: show variables &
stereotype, in «» properties, in {} Underline any class variables and methods
methods.
«class» Or write static as part of the
{abstract} declaration.
«interface»

Visibility Markers Show Java Declaration

Date - is private Date


# is protected
− day + is public − int day
− month @ is <package>* − int month
− year − int year

+ Date() *) UML does not + Date()


+ getDay() define a visibility + int getDay()
+ getMonth() marker for Java’s + int getMonth()
+ getYear() package visibility. + int getYear()
+ getDayOfWeek() Using @ is our own + int getDayOfWeek()
# checkDay() idea. # boolean checkDay(int d, int m, int y)
+ nextDay() BTW: Using + void nextDay()
+ daysBetween() package visibility is + int daysBetween(Date d1, Date d2)
# calcDayNumber() not recommended. # int calcDayNumber(Date d)

Suppressing the visibility marker does not You can show the declaration, or just
mean the visibility is undefinded or public! the name of methods & variables

You can show the visibility markers (+, #, −, @), show the Java visibility modifiers (public,
protected, private or <package>) as part of the declaration, or suppress all visibility information.

UML for Java Quick Reference M. Hauswirth, hrm@isbiel.ch, 1998


Relationships between Classes

Association (uses a)

Floor 1 * Turtle Composition (contains a)

Human Head
Multiplicity:
A Turtle walks on
1 means: exactly one
exactly one floor. A Human has a Head. A Head is an
0..1 means: zero or one
A floor may be used by inherent part of a Human, it is
1..* means: one or more
multiple turtles. "exclusively owned" by the Human.
* means: zero, one or more

Inheritance (is a)

Human «interface» «interface»


A Student is a EventListener ActionListener
Human.
Student extends
Human.
Student «interface»
ActionListener TestApplet

Shape
ActionListener is an TestApplet is an
EventListener. ActionListener.
Circle Rectangle ActionListener extends TestApplet implements
EventListener. ActionListener.

Abstract Classes, Abstract Methods & Interfaces

abstract class: interface:


write name in specify «interface» stereotype and write name in Pane
italics or specify italics or specify {abstract} property
{abstract} property # width
«interface» «interface» # height
Vehicle DirectoryListener ActionListener + paint()
{abstract} {abstract}
abstract
+ actionPerformed()
− speed method:
write + directoryChanged()
DirectoryPane
+ run() name in extends Pane.
+ setSpeed() italics or
DirectoryPane
+ getSpeed() specify
implements DirectoryPane
{abstract}
DirectoryListener
property
and ActionListener. − currentDir()
Car
+ actionPerformed()
+ directoryChanged()
+ run() + getDirectory()

UML for Java Quick Reference M. Hauswirth, hrm@isbiel.ch, 1998

Vous aimerez peut-être aussi