Download presentation
Presentation is loading. Please wait.
Published byFrederica McCoy Modified over 9 years ago
1
CH-4 Advanced class modeling
2
BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different notations. The model includes two classes, Book and Chapter, with the relationship, Book is composed of Chapters. In UML, classes are depicted by rectangles and aggregation associations by a line terminated with a diamond. In the Booch notation, classes are depicted by clouds, and aggregation associations are depicted with a line terminated with a solid circle.
3
UML DIAGRAMS RELATIONSHIPS BETWEEN CLASS/OBJECT DIAGRAMS – Associations and Links: A link is a solid line between objects/classes. An association is a bundle of relationships between same. (An inter-object class link represents a state rather than relationship.) (Fig 2-22, Fig 2-23) – Roles: Labels at the ends of a link or association, and help distinguish between multiple associations originating from a class and also clarify purpose of the association (Fig 2-23)
4
Cont… – Multiplicity: A set of integers (or range of integers) labeling the end of a link or association. The specified number (or range) indicate the number of associations – originating from the instance to the association end. [There could a one-to-one, one- to-many, and many-to-many associations.] (Fig 2-22, Fig 2-25) – Association Class: When an association link carries more information (attributes and operations) to be represented as a class and depicted by a class symbol. – Ex.: The AC is connected by a dashed line to the link (which connects the principal classes). A transformed AC (which removes the principal link) results in a two, one-to-one associations between the AC and each of the principal classes). (Fig 2-24 and Fig 2-25)
5
Continue.. – Aggregation or Composition: A one-to-many association modeling which represents the concept of an aggregation, with hierarchical representation. [Depicted by a simple line with a diamond at the container end of the association – Fig 2-26] – Generalization: Representing the ‘common’ attributes and operations in a general class, leaving specifics to subordinate classes, with inheritance to create a (abstract) superclass and subclasses (Fig 2-27) – Operations/Methods: Operations specify the signature of object behaviors (a set of which represents a service of the class) and Methods define the implementations of the operations. [Request for a service is via message exchanges between objects in the client-server object classes.] (Fig 2-28)
6
Figure 2-15. An example of a UML use case diagram: Incident initiation in an accident management system. Associations between actors and use cases represent information flows. In UML, these associations are bidirectional: They can represent the actor initiating a use case (e.g., FieldOfficer initiates ReportEmergency ) or a use case providing information to an actor (e.g., ReportEmergency notifies Dispatcher ).
7
Figure 2-11. An example of abstract class (UML class diagram). OrganicCompound is never instantiated and only serves as a generalization.
8
EmergencyReport Incident FieldOfficer name:String badgeNumber:Integer Dispatcher name:String badgeNumber:Integer author incidentsGenerated reportsGenerated initiator reports 1 * 1 * 1..* 1 Figure 2-22. An example of a UML class diagram: classes that participate in the ReportEmergency use case. Detailed type information is usually omitted until object design
9
report_1291incident_1515 bob:FieldOfficer name = “Bob D.” badgeNumber = 132 john:Dispatcher name = “John D.” badgeNumber = 12 alice:FieldOfficer name = “Alice W.” badgeNumber = 23 Figure 2-23. An example of a UML object diagram: objects that participate in the warehouseOnFire scenario.
10
Incident FieldOfficer name:String badgeNumber:Integer Allocates role:String notificationTime:Time resources incident 1 1..* Figure 2-24. An example of an association class (UML class diagram).
11
Incident FieldOfficer name:String badgeNumber:Integer Allocation role:String notificationTime:Time resources incident1 1..* 1 1 Figure 2-25. Alternative model for Allocation (UML class diagram).
12
** PoliceStation * * 1 1 1 1 State Directory CountyPoliceOfficer File Township Figure 2-26. Examples of aggregations (UML class diagram). A State contains many Counties, which in turn contains many Townships. A PoliceStation has many PoliceOfficers. A file system Directory contains many Files.
13
EmergencyReport Incident FieldOfficer Dispatcher author initiator reportsGenerated incidents 1 * 1 * 1..* 1 PoliceOfficer name:String badgeNumber:Integer Figure 2-27. An example of a generalization (UML class diagram). PoliceOfficer is an abstract class which defines the common attributes and operations of the FieldOfficer and Dispatcher classes.
14
Figure 2-44. An example of constraint (UML class diagram).
15
Incident assignResource(r) close() Figure 2-28. Examples of operations provided by the Incident class (UML class diagram).
16
4.3 a. A country has a capital city. Association. A capital city and a country are distinct things so generalization certainly does not apply. You could argue that a capital city is a part of a country and thus they are related by aggregation. b. A dining philosopher uses a fork. Association. Dining philosophers and forks are completely distinct things and are therefore not in a generalization relationship. Similarly, neither object is a part of the other and the relationship is not aggregation. 16
17
17 c. A file is an ordinary file or a directory file. Generalization. The word “or” often is an indicator of generalization. File is the superclass and OrdinaryFile and DirectoryFile are subclasses. d. Files contain records. Aggregation. The word “contain” is a clue that the relationship may be aggregation. A record is a part of a file. Some attributes and operations on files propagate to their constituent records. e. A polygon is composed of an ordered set of points. Aggregation. The phrase “is composed of” should immediately make you suspicious that there is an aggregation. An ordered set of points is a part of a polygon. Some attributes and operations on a polygon propagate to the corresponding set of points.
18
4.3 f. A drawing object is text, a geometrical object, or a group. Generalization. Once again, the word “or” should prompt you to think of generalization. Drawing Object is the superclass. Text, Geometrical Object, and Group are subclasses. g. A person uses a computer language on a project. Ternary association. Person, Computer Language, and Project are all classes of equal stature. The association cannot be reduced to binary associations. None of these classes are a-kind-of or a-part-of another class. Thus generalization and aggregation do not apply. Selection Buffer Sheet Box Collection Line Line Segment Point 2 Figure A4.2 Generalization of the classes Selection, Buffer, and Sheet into the class 18
19
Continue… h. Modems and keyboards are input / output devices. Generalization. The keyword “are” is the clue. Modem and Keyboard are the subclasses; InputOutputDevice is the superclass. i. Classes may have several attributes. Association or aggregation. It depends on your perspective and the purpose of the model whether aggregation applies. j. A person plays for a team in a certain year. Ternary association. Person, Team, and Year are distinct classes of equal stature. 19
20
Continue… k. A route connects two cities. Association. Either Route is a class associated with the City class, or Route is the name of the association from City to City. l. A student takes a course from a professor. Ternary association. Student, Course, and Professor are distinct classes of equal stature. 20
21
4.11 To find the superclass of a generalization using Figure E4.3, first query the association between Generalization and GeneralizationRole to get a set of all roles of the given instance of Generalization. Then sequentially search this set of instances of GeneralizationRole to find the one with roleType equal to superclass. (Hopefully only one instance will be found with roleType equal to superclass, which is a constraint that the model does not enforce.) Finally, scan the association between GeneralizationRole and Class to get the superclass. Figure A4.9 shows one possible revision which simplifies superclass lookup. To find the superclass of a generalization, first query the association between Generalization and SuperclassRole. Then query the association between SuperclassRole and Class to find the corresponding instance of Class.
22
4.11
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.