Title: UML Classes Sipping from the Fire Hose
1UML ClassesSipping from the Fire Hose
2Quiz
- Draw a fully expanded class icon and identify
which compartment holds what information
3Session Goals
- Understand and be comfortable with the following
UML notations - UML Class
- Various UML Associations
4UML Class Diagrams
- In software design, the most common diagram is
the class diagram - Class diagrams depict classes in a software
system and the relationships between the classes
5Forms of the UML Class Notation
Fully Elided
Fully Expanded
ClassName
ClassName
ltattributesgt
ltoperationsgt
Partially Elided (operations only)
Partially Elided (attributes only)
ClassName
ClassName
ltattributesgt
ltoperationsgt
6Visibility and Static notations
Visibility Notations Public ltnamegt Private -
ltnamegt Protected ltnamegt
Public, private, and protected have the usual
interpretations.
Static Underline ltnamegt
Static has the usual interpretation. Also
referred to as class-scope.
7Attributes
- Attributes represents characteristics of a class
- Sometimes referred to as the class state data
- Attributes can be specified in several forms
Generic Form for an Attribute
stereotypevisibility name type initial
value
8Attribute Examples
No information about type No information about
default value Attribute is not static (has
instance scope) Unspecified visibility (often
assumed private)
name
No information about type No information about
default value Attribute is not static (has
instance scope) Attribute is protected
name
Is an instance or reference to an instance of
the class, String (language dependent) No
information about default value Attribute is not
static (has instance scope) Attribute is protected
name String
9Attribute Examples
No information about type No information about
default value Attribute is static (has class
scope) Attribute is private
- count
Is an instance of int Has initial value of
0 Attribute is static (has class scope) Attribute
is public
count int 0
Example of a constant attribute (uses the frozen
constraint)
name String Fred frozen
10Operations
- Operations represent processes that a class knows
how to execute - Operations, like attributes, have several
variations on how the can be specified
Generic Form for an Operation
stereotype visibility static name
(parameter list) return type
Parameter List is defined as direction name
type default value
Direction is either in, out, or inout. When
unspecified, it is assumed to be in.
11Operation Examples
No information about return type No information
about parameters Operation is not static (has
instance scope) Visibility unspecified (often
assumed public)
getCount()
Returns an instance of int No information about
parameters Operation has instance scope Operation
is public
getCount() int
Fully specified Operation
updateName (in to String) Status
12Operation Examples
13Class Examples Elided vs. Expanded
Fully Elided
BillardBall
Fully Expanded
BillardBall
_position Position _direction float
_energy float
init(in atPosition Position) void hitBy (in
ball BillardBall) void currentPosition()
Position
14Class Example - Sale
C
UML - Fully expanded
class Sale protected bool _isComplete
Date _date Time _time ItemList
_items public Sale() Date date()
Time time() bool isComplete() void
addItem (Item item)
Sale
_isComplete bool _date Date
_time Time _items ItemList
Sale() date() Date time()
Time isComplete() bool addItem() void
15Class Example - Sale
C
UML - Fully Elided
class Sale protected bool _isComplete
Date _date Time _time ItemList
_items public Sale() Date date()
Time time() bool isComplete() void
addItem (Item item)
Sale
UML - Partially Elided
Sale
Sale() date() Date time()
Time isComplete() bool addItem() void
16Class Example - Dog
Java
UML - Fully expanded
public class Dog protected Breed _breed
protected int _ageInYears protected Name
_name protected boolean _isFixed
protected boolean _isHungry protected boolean
_isAsleep protected boolean _isBarking
public boolean isHungry() ... public
boolean isAsleep() ... public void eat()
... public void speak() ... public
void hush() ...
Dog
_breed Breed _ageInYears int _name
Name _isFixed boolean _isHungry
boolean _isAsleep boolean _isBarking
boolean
isHungry() boolean isAsleep() boolean eat()
void speak() void hush() void
17Class Example Dog
Java
UML - Fully Elided
public class Dog protected Breed _breed
protected int _ageInYears protected Name
_name protected boolean _isFixed
protected boolean _isHungry protected boolean
_isAsleep protected boolean _isBarking
public boolean isHungry() ... public
boolean isAsleep() ... public void eat()
... public void speak() ... public
void hush() ...
Dog
UML - Partially Elided
Dog
isHungry() boolean isAsleep() boolean eat()
void speak() void hush() void
18Exercise
- Moving forward, we may encounter a potential
problem with this representation of the class Dog - What might the problem be?
UML Representation Of Dog
Dog
breed Breed ageInYears int name
Name isFixed boolean isHungry
boolean isAsleep boolean
Dog() isHungry() boolean isAsleep()
boolean eat() void speak()
void hush() void
19Perspectives
- UML diagrams can communicate varying levels of
information - Different levels serve different purposes
- Class diagrams represent the entities within a
system and their relationships - There are three perspectives common to class
diagrams - Conceptual
- Specification
- Implementation
Note The names of the perspectives are not part
of UML and vary widely. We use them here mostly
for example.
20Class Diagrams Conceptual Perspective
- The conceptual perspective is used to communicate
a very coarse structure of the system - Generally contains classes using a fully elided
notation - This perspective is often as independent of any
technology as possible - The classes could be implemented in any language
21Class Diagrams Specification Perspective
- The specification perspective is used to
communicate interfaces that a class has - For example, the operations defined for the class
- Class representations in this perspective most
likely will not have attributes - The partially expanded form is often used
- The perspective is suggesting behavior without
the details of the behavior - This perspective will try to remain as language
neutral as possible - Use of terms like Boolean are not taken
literally
22Class Diagrams Implementation Perspective
- The implementation perspective is used to
communicate the detailed design of the system - Class representations are one step away from
source code - At this point, language or technology specific
details may begin to materialize in the class
representations - Full specifications of operations and attributes
exist
23Class Diagrams Our purposes
- Many of the class diagrams we will discuss or
generate will straddle the conceptual and
specification perspective - This is often the focus of modeling
- It is useful to begin modeling at the conceptual
level and later evolve a specification perspective
24Exercise
Generate two class diagrams (a conceptual view
and a specification view) which contain classes
for Cookbook Recipe Ingredient