Lesson 6 - Class
Lesson 6 - Class
Big questions
What is UML?
Why should I bother? Do people really use UML?
UML diagrams
class diagrams (today)
sequence diagrams
...
Introduction to UML
UML: pictures of an OO system
programming languages are not abstract enough for OO
design
UML is an open standard; lots of companies use it
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 btwn. classes
generalization: an inheritance relationship
inheritance between classes
interface implementation
one-to-many
one rectangle list can contain many rectangles
Car
1
Association types 1
aggregation
Book
composition: "is entirely made of" composition
stronger version of aggregation 1
the parts live and die with the whole *
symbolized by a black diamond
Page
Customer Simple
1
Class Aggregation
Checkout Screen
DVD Movie VHS Movie Video Game
Class diagram example 3
StudentBody Student
1 100
- firstName : String
+ main (args : String[]) - lastName : String
- homeAddress : Address
- schoolAddress : Address
+ toString() : String
Address
- streetAddress : String
- city : String
- state : String
- zipCode : long
+ toString() : String
Tools for creating UML diags.
Violet (free)
http://horstmann.com/violet/
Rational Rose
http://www.rational.com/