Class Diagrams October 16 2001 Class Diagrams 1
Class Diagrams October 16, 2001 Class Diagrams 1
(Design) Class Diagrams (1) z A class diagram is a visual representation of various classes and their relationships as identified during design. z Information in class diagram includes: yclasses, associations, and attributes yinterfaces with operations and constants ymethods yattribute type information ynavigability ydependencies October 16, 2001 Class Diagrams 2
Class diagrams (2) z Class diagrams are generally created after or in parallel with the interaction diagrams. z Interaction diagrams are used to identify classes and the methods they provide. z Conceptual model is also useful in deriving classes by addition of detail. z Classes are considered software entities and not real-world concepts. October 16, 2001 Class Diagrams 3
Making class diagrams (1) z Identify all classes by examining interaction diagrams. z Draw them in a class diagram. z Duplicate the attributes from the associated concepts shown in the conceptual model. z Add method names by examining interaction diagrams. z Add type information to the attributes and methods. October 16, 2001 Class Diagrams 4
Making class diagrams (2) z Add the associations needed for visibility. z Add navigability arrows to indicate the direction of attribute visibility. z Add dependency relationships to indicate nonattribute visibility. October 16, 2001 Class Diagrams 5
Conceptual model versus class diagrams (1) z A Sale in a conceptual model represents a system concept. A Sale in a class diagram represents a software entity. October 16, 2001 Class Diagrams 6
Conceptual model versus class diagrams (2) POST 1 captures Sale 1 Date is. Complete: boolean time Conceptual model POST captures 1 1 Date is. Complete: boolean time make. Line. Item() time October 16, 2001 Sale Date is. Complete: boolean Class Diagrams Software components 7
Class diagrams: notables (1) z create is a special language independent UML message to indicate instantiation and initialization. As this is a common operation, it is often omitted from class diagrams. z Access methods for class attributes are also omitted from class diagrams to reduce clutter. z Messages to a multiobject are not shown as methods in the class whose objects are contained in a multiobject. October 16, 2001 Class Diagrams 8
Class diagrams: notables (2) z It is recommended that UML syntax be used for method naming. This will keep naming language independent. UML format: method. Name(parameter. List) z Should all type information be shown in a class diagram? y. If automatic code generation is desired then YES. y. If the sole purpose is to use the diagram as a communication aid, then all type information is not of any significant value. (See Fig 21. 7 of T 1. ) October 16, 2001 Class Diagrams 9
Class diagrams: navigability (1) POST will likely have an attribute pointing to Sale. Navigability arrow: POST objects are connected uni-directionally to Sale objects. POST 1 captures 1 Date is. Complete: boolean Sale Date is. Complete: boolean time make. Line. Item() time No navigability arrow. . Sale does not have connection to POST. October 16, 2001 Class Diagrams 10
Class diagrams: navigability (2) z It is recommended that associations be adorned with navigability arrows. z Navigability is determined by visibility. y. A sends a message to B. y. A creates an instance of B. y. A needs to maintain a connection to B. z Example: Examine Figures 21. 9 and 21. 10 on pages 266 -267. Why are navigability arrows not provided in the conceptual model ? October 16, 2001 Class Diagrams 11
Class diagrams: dependency z In UML a dependency relationship indicates that one element has knowledge of another element. z It is illustrated with a dashed arrow. z Non-attribute visibility…arising from parameters, global, or locally declared items is illustrated by dashed arrows. z See Figure 21. 11, page 268, for dependency relationships. October 16, 2001 Class Diagrams 12
Class diagrams: other notations z Initial values of attributes z Return value type z Abstract method z Parameters z Visibility October 16, 2001 Class Diagrams 13
Summary z. What did we learn? y. What is a class diagram ? y. How to derive a class diagram from interaction diagrams ? y. Notational details for class diagrams. October 16, 2001 Class Diagrams 14
- Slides: 14