UML Class Models
Summary
Classes
A class is a description of a similar set of instances
Candidates for classes include:
- domain objects
- roles
- events
- interactions
Name Component
Should be a noun
Italic names means abstract class
- Describe properties of subclasses
Classes can also have stereotypes
- a way of extending base UML
Attributes
Instance methods
Generally, it’s of the form [visibility] name: type [= defaultValue]
Visibility modifiers:
- +public
- -private
- #protected
- ~package
Optional multiplicity and ordering
Optional derivation
Operations
[visibility] name([inputs]): [returnType]
Inputs can be of multiple types:
- in
- out
- inout
out and inout params roughly translate to parameters passed by reference
Properties:
- {query}
- {concurrency}
- {abstract}
- Class Scope
Advanced Features
- Interfaces
- Icons for requires and provides
- Parameterized Classes
- Generics & templates
- Nested Classes
- Classes in Classes
- Composite Objects
- Class diagrams inside class rectangles
Relationships
Verbs
Types of Relationships:
- Associations
- People drive vehicles
- Generalizations
- Cars are a type of vehicle
- Dependency
- Change in pollution laws means a change in car
- Also “coupling”
Associations
Solid line between classes
Polygon Contains Points
Associations can contain
- name
- association class
- Associations that have class properties
- Class that has dotted line dotted in the middle of solid line
- aggregation or composition
Open diamonds mean aggregation
Closed diamonds mean composition
- Polygon “is made up of” points
Navigability is shown by arrows
Numbers, ranges, and * denote multiplicity
“bundle” is a role name in the example
- “GraphicsBundle ‘plays the role of’ bundle”
Associations can have constraints
Associations can be recursive
- Make sure to name those
Associations can be qualified
- Think like foreign key
Aggregation and Composition
Aggregations don’t say anything about the lifetimes of the participant objects, composition does
If you destroy a house, you also destroy the rooms, so a house has a composition of rooms, not aggregation
A constituent can only belong to one composition
Composition is transitive, aggregations are not
Links
Links are instances of associations
Association = “Employer hires person”
Link = “IBM hires Bob”
Generalization
Solid line with triangle
Arrow goes on super class
Generalization is not the same as inheritance
Generalization is a modeling technique, inheritance is an implementation technique