UML Class Diagrams
UML Class Diagrams
Suggested reading:
Practical UML: A hands on introduction for developers
http://dn.codegear.com/article/31863
UML Distilled Ch. 3, by M. Fowler
1
Design phase
• design: specifying the structure of how a software
system will be written and function, without actually
writing the complete implementation
• attributes (optional)
– should include all fields of the object
– visibility: + public
# protected
- private
~ package (default)
/ derived
– underline static attributes
– attribute example:
- balance : double = 0.00
Class operations / methods
• operations / methods
– visibility name (parameters) : return_type
– visibility: + public
# protected
- private
~ package (default)
– underline static methods
– parameter types listed as (name: type)
– omit return_type on constructors and
when return type is void
– method example:
+ distance(p1: Point, p2: Point): double
Comments
• represented as a folded note, attached to the
appropriate class/method/etc by a dashed line
Relationships between classes
• generalization: an inheritance relationship
– inheritance between classes
– interface implementation
3. navigability (direction)
Multiplicity of associations
one-to-one
each student must carry exactly one ID card
one-to-many
one rectangle list can contain many rectangles
Car
Association types 1
aggregation
• aggregation: “is part of” 1
Engine
– symbolized by a clear white diamond
composition
– stronger version of aggregation
1
– the parts live and die with the whole
*
– symbolized by a black diamond
Page
Customer
1 Simple
Class Aggregation
Composition Simple
Generalization
Association
Checkout Screen
DVD Movie VHS Movie Video Game
Class diagram example: student
StudentBody Student
1 100
- firstName : String
+ main (args : String[]) - lastName : String
- homeAddress : Address
- schoolAddress : Address
+ toString()
toString() : String
Address
- streetAddress : String
- city : String
- state : String
- zipCode : long
+ toString() : String
Tools for creating UML diagrams
• Violet (free)
– http://horstmann.com/violet/
• Rational Rose
– http://www.rational.com/