Download presentation
Presentation is loading. Please wait.
Published byKelley Moore Modified over 8 years ago
1
Class diagram Used for describing structure and behaviour in the use cases Provide a conceptual model of the system in terms of entities and their relationships Used for requirement capture, end- user interaction Detailed class diagrams are used for developers
2
Class representation Each class is represented by a rectangle subdivided into three compartments Name Attributes Operations Modifiers are used to indicate visibility of attributes and operations. ‘+’ is used to denote Public visibility (everyone) ‘#’ is used to denote Protected visibility (friends and derived) ‘-’ is used to denote Private visibility (no one) By default, attributes are hidden and operations are visible.
3
An example of Class
4
Finding Classes Classes are identified by examining the nouns and noun phrases in scenarios Nouns found may be: Objects Description of the state of an object External entities and/or actors None of the above
5
Finding Classes … Beware that: Several terms may refer to the same object One term may refer to more than one object Natural language is very ambiguous Therefore The list of nouns must be filtered.
6
Operation A operation is a service that can be requested from an object to effect behaviour. List of operations is dependent on the problem domain. Lecturer from Registrar’s perspective Lecturer from leave clerk’s perspective
7
Operation … Operation should be named to indicate their outcome. CalculateBalance() Poorly named getBalance() Better named
8
Operation … Operation should be named from the perspective of the supplier, not the client. E.g. In a pertrol station, petrol is received from the pump. Dispense() Good name receiveGas() Bad name
9
Operation … Operation has signature. The operation signature consists of Optional argument list Return type During analysis it is NOT mandatory to fill in the operation signature. It may be delayed until design.
10
Attributes An attribute is a data definition held by instances of a class. Attributes do not have behaviour Attribute names are simple nouns or noun phrases Each attribute should have a clear, concise definition, e.g. for the Student class Good attributes are name, major. Bad attribute e.g. is selectedCourse (this is a relationship!)
11
Attributes … Similar to operations, list of attributes is dependent on the problem domain. Banker’s perspective Name, address, dateOfBirth, account no. Doctor’s perspective Name, address, dateOfBirth, height, weight
12
Attributes … A ‘derived attributes’ is an attribute whose value may be calculated based on the value of other attribute(s). Used when there is not enough time to recalculate the value every time needed Trades off runtime performance versus memory required.
13
Attributes … Each attribute has Data type Optional initial value During analysis, it is NOT mandatory to complete the attribute definition, this information may be delayed until design.
14
Attributes … How are attributes discovered? Many attributes are discovered in the flow of events for the use cases Look for nouns that were not considered good candidate classes Others are discovered when the class definition is created Domain expertise can also provide good attributes
15
Class Relationships There are two kinds of Relationships Generalization (parent-child relationship) Association (student enrolls in course) Associations can be further classified as Aggregation Composition
16
Subtype2 Supertype Subtype1 Generalisation - Generalization expresses a parent/child relationship among related classes. - Used for abstracting details in several layers Regular Customer Loyalty Customer Example: Regular Customer Loyalty Customer or:
17
Generalisation
18
Association represents relationship between instances of classes Student enrolls in a course Courses have students Courses have exams etc. Association has two ends Names (e.g. enrolls) Multiplicity (e.g. One course can have many students) Navigability (unidirectional, bidirectional) Association
19
To clarify its meaning, an association may be named. The name is represented as a label placed along the association line, midway between the class notations. An association name is usually a verb or verb phrase. Association Name
21
Multiplicity is the number of instances of one class related to ONE instance of the other class. For each association, there are two multiplicity decisions to make; one for each end of the association. Association Multiplicity
22
Many * Exactly one 1 Zero or more0..* One or more1..* Zero or one 0..1 Specified range 2..4 Association Multiplicity …
24
Class Relationships
25
Other Relationships …
26
Association: Composition Class W Class P 1 Class P 2 Composition: expresses a relationship among instances of related classes. It is a specific kind of Whole-Part relationship. It expresses a relationship where an instance of the Whole-class has the responsibility to create and initialize instances of each Part-class. It may also be used to express a relationship where instances of the Part-classes have privileged access or visibility to certain attributes and/or behaviors defined by the Whole-class. Composition should also be used to express relationship where instances of the Whole-class have exclusive access to and control of instances of the Part-classes. Composition should be used to express a relationship where the behavior of Part instances is undefined without being related to an instance of the Whole. And, conversely, the behavior of the Whole is ill-defined or incomplete if one or more of the Part instances are undefined. Whole Class Part Classes Automobile Engine Transmission Example [From Dr. David A. Workman]
27
Association: Aggregation Class C Class E 1 Class E 2 AGGREGATION Aggregation: expresses a relationship among instances of related classes. It is a specific kind of Container- Containee relationship. It expresses a relationship where an instance of the Container-class has the responsibility to hold and maintain instances of each Containee-class that have been created outside the auspices of the Container-class. Aggregation should be used to express a more informal relationship than composition expresses. That is, it is an appropriate relationship where the Container and its Containees can be manipulated independently. Aggregation is appropriate when Container and Containees have no special access privileges to each other. Container Class Containee Classes Bag Apples Milk Example [From Dr. David A. Workman]
28
Aggregation vs. Composition CompositionComposition is really a strong form of aggregation components have only one owner components cannot exist independent of their owner components live or die with their owner e.g. Each car has an engine that can not be shared with other cars. Aggregations may form "part of" the aggregate, but may not be essential to it. They may also exist independent of the aggregate. e.g. Apples may exist independent of the bag.
29
Aggregation vs. Composition
30
Class Diagram Example
31
Class Diagram Example …
33
Summary Derivation of classes from use case description Class name Attributes Operations Refinement of list of classes Class relationships
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.