Class Diagram Notation Lecture Oo12 Classes Packages
Dec 28, 2015
Class Diagram Notation
Lecture Oo12
Classes
Packages
References
Ambler, S., The Object Primer, Cambridge Univ. Press, 2001, Section 6.3, 6.9, 7.1, 7.2,
Teaching Points
Class Characteristics Packages Package Diagrams
Review
What are the different visibility types? Describe each type When does a visibility type make sense
to use?
Access Control
also known as visibility in UML (encapsulation visibility vs. object visibility)
Three kinds of encapsulation visibility– Private– Protected– Public
Encapsulation Visibility Markings - (or a pad lock) = Private # (or a key) = Protected + (or no marking) = Public
Example (Attribute/Operation Markings)
ExampleClass
privateAttprotectedAttpublicAtt
privateOp()protectedOp()publicOp()
Example (Relationship Markings)
ExampleClass
privateAttprotectedAttpublicAtt
privateOp()protectedOp()publicOp()
AnotherExample-privaterole+publicrole
#protectedrole
Static Class Members
Static attributes (data members) are held in the program static data space
There is only one copy of such data for the class (i.e. one for all object instances of that class)
These can be thought of as “Class data” Can be used to reduce global data
Example (Static Attributes)
ExampleClass
$ privateAttprotectedAttpublicAtt
privateOp()protectedOp()publicOp()
Class Specifications
Diagrams by themselves do not provide enough detail to fully understand the problem/solution
Specifications provide a detailed understanding of the class and its semantics
Diagrams really must be accompanied by some specification
Class name: Heater
Category: Logical View Documentation: This is an abstract class that provides a common interface to heaters in the system. A client object can provide a required temperature to a heater. The heaters have a temperature sensor built in and feedback from this sensor is used to contol the temperature.
External Documents: Export Control: Public Cardinality: n Hierarchy: Superclasses: none Associations:
<no rolename> : TempController in association <unnamed>
Public Interface: Operations: setTemp
Private Interface: Attributes: desiredTemp : Temperature The currently required temperature for the object to be heated.
Implementation: Attributes: desiredTemp : Temperature The currently required temperature for the object to be heated.
State machine: No Concurrency: Sequential Persistence: Transient
Operation Specification
Operation name: getTemp
Public member of: TempRamp Return Class: Temperature Arguments:
Time currentTime Documentation: Given a normalized time this function returns the temperature computed from the ramp function.
Concurrency: Sequential
Package Diagrams
Large flat (non-hierarchical) class diagrams are complex and hard to understand
It is hard to see structure It is hard to find a class for maintenance
or reuse
Package Diagrams
Solution:– apply abstraction, decomposition and
hierarchy– group the classes together in higher level
units
Packages
A grouping of mutually dependent classes
Apply rules of coupling and cohesion Packages are elements of a class
diagram (i.e. package diagrams are class diagrams)
Package Dependencies The relationship between packages is the
Dependency relationship Classes in packages have visibility (access
control) applied to them for information hiding purposes– only some of the classes are visible (public) to
users of the package– some classes are private (implementation) to the
package and can be changed without effecting users of the package
Example
Rose package diagram for Chemical Process Controller
Flat Model
VatHeater
setTemp()
(from Drivers)PipeHeater
setTemp()
(from Drivers)
Heater
setTemp()
(from Drivers)
ProcessController(from ControllerLogic)
TempRamp
getTemp()
(from ControllerLogic)
Clock
getTime()
TempController
setJob()
(from ControllerLogic)
11
1
-controlledHeater
1
1
0..*
1
0..*
heaterList
-currentRamp
-systemClock
Package Diagram (top level)
ControllerLogic
Drivers NewPackage
global
Controller Logic Package
Heater
setTemp()
(from Drivers)
ProcessControllerTempRamp
getTemp()
Clock
getTime()
(from Logical View)TempController
setJob()
-controlledHeater
1
-currentRamp
-systemClock
11
1
1
0..*
1
0..*
heaterList
Drivers Package
VatHeater
setTemp()
PipeHeater
setTemp()
Heater
setTemp()
System Package
Clock
getTime()
(f rom Logical View )
Teaching Points
Class Characteristics Packages Package Diagrams