11 Class Diagrams


Published on

Published in: Technology
1 Comment
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

11 Class Diagrams

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