Class Diagram Notation Lecture Oo12 Classes Packages
References n Ambler, S., The Object Primer, Cambridge Univ. Press, 2001, Section 6.3, 6.9, 7.1, 7.2,
Teaching Points n Class Characteristics n Packages n Package Diagrams
Review n What are the different visibility types? n Describe each type n When does a visibility type make sense to use?
Access Control n also known as visibility in UML (encapsulation visibility vs. object visibility) n Three kinds of encapsulation visibility –Private –Protected –Public
Encapsulation Visibility Markings n - (or a pad lock) = Private n # (or a key) = Protected n + (or no marking) = Public
Example (Attribute/Operation Markings)
Example (Relationship Markings)
Static Class Members n Static attributes (data members) are held in the program static data space n There is only one copy of such data for the class (i.e. one for all object instances of that class) n These can be thought of as “Class data” n Can be used to reduce global data
Example (Static Attributes)
Class Specifications n Diagrams by themselves do not provide enough detail to fully understand the problem/solution n Specifications provide a detailed understanding of the class and its semantics n 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: : TempController in association 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: TimecurrentTime Documentation: Given a normalized time this function returns the temperature computed from the ramp function. Concurrency:Sequential
Package Diagrams n Large flat (non-hierarchical) class diagrams are complex and hard to understand n It is hard to see structure n It is hard to find a class for maintenance or reuse
Package Diagrams n Solution: –apply abstraction, decomposition and hierarchy –group the classes together in higher level units
Packages n A grouping of mutually dependent classes n Apply rules of coupling and cohesion n Packages are elements of a class diagram (i.e. package diagrams are class diagrams)
Package Dependencies n The relationship between packages is the Dependency relationship n 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 n Rose package diagram for Chemical Process Controller
Flat Model
Package Diagram (top level)
Controller Logic Package
Drivers Package
System Package
Teaching Points n Class Characteristics n Packages n Package Diagrams