140 likes | 318 Views
TK2023 Object-Oriented Software Engineering. CHAPTER 11 CLASS DIAGRAMS. INTRODUCTION. UML provides class diagrams for illustrating classes, interfaces and their associations. Class diagrams are used for static object modelling.
E N D
TK2023 Object-Oriented Software Engineering CHAPTER 11 CLASS DIAGRAMS
INTRODUCTION • UML provides class diagrams for illustrating classes, interfaces and their associations. • Class diagrams are used for static object modelling. • Note that class diagrams are also used for visualizing domain models. • The term design class diagram (DCD) will be used to refer to the class diagram used in the design perspective (as opposed to the conceptual perspective).
Sale Domain Model Register Captures 1 1 time conceptual ... isComplete : Boolean perspective / total Register Sale Design Model time ... 1 isComplete : Boolean DCD ; design endSale () currentSale / total perspective enterItem (...) makeLineItem (...) makePayment (...)
ATTRIBUTES • Attributes of a class can be shown in the attribute text notation. • Use this notation for data type objects i.e. objects for which unique identity is not important. Person name : String dob : Date ...
Register Sale 1 ... ... currentSale ... ... • Attributes of a class can also be shown in the association line notation. • Note the following style: • a navigability arrow pointing from the source to the target object • a multiplicity at the target end, but not the source end • a rolename only at the target end to show the attribute name • no association name
Car Person + year : int # name : String public attribute private attribute protected attribute • Visibility marks are used to indicate whether an attribute is public, private or protected. • If no visibility is given, attributes are usually assumed private. 1 - owner
When using class diagrams to show domain models: • show association names • avoid navigation arrows
OPERATIONS AND METHODS • Examples of operations: • An operation is assumed public if visibility is not indicated. Rectangle + setLength(int val) + getArea() : int
An operation is not a method. In UML, an operation is a declaration whereas a method is its implementation. • getter and setter operations are usually filtered out in class diagrams because they generate high noise-to-value ratio. Example: getArea(), setLength(val)
Circle Rectangle length : int height : int radius : int ... ... INHERITANCE • Inheritance relationships between a superclass and its subclasses can be expressed in a class diagram as shown below. Shape #colour : Colour ...
DEPENDENCY RELATIONSHIP • A dependency relationship exists between a client element (of any kind, including classes, packages, use cases, etc) and a supplier element if the former has knowledge of the supplier element and that a change in the supplier could affect the client.
Example: Suppose the class Workshop has the following operation void addClient(Customer c, Vehicle v) Vehicle ... ... Workshop ... ... Customer ... ...
Note that the dependency relationship is a very general one. For example, an inheritance relationship is actually a kind of dependency relationship. • Use the guideline below for DCDs: Use the dependency line to show the following types of dependencies between objects: • global • parametric • local
RELATIONSHIP BETWEEN INTERACTION AND CLASS DIAGRAMS • When interaction diagrams are drawn, a set of classes and their methods emerge from doing dynamic object modelling. • This means that definitions of class diagrams can be generated from interaction diagrams. • This suggests a linear ordering of drawing interaction diagrams before class diagrams. • In practice, these complementary dynamic and static views are drawn concurrently.