22
CH-4 Advanced class modeling

CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

Embed Size (px)

Citation preview

Page 1: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

CH-4

Advanced class modeling

Page 2: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

Book ChapterN

composed-of

Booch

Book Chapter

composed-of

UML1 *

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.

Page 3: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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)

Page 4: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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)

Page 5: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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)

Page 6: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

Report Emergency

FieldOfficer DispatcherOpenIncident

AllocateResources

FRIEND

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).

Page 7: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

OrganicCompound

Benzene

Figure 2-11. An example of abstract class (UML class diagram). OrganicCompound is never instantiated and only serves as a generalization.

Page 8: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

EmergencyReport Incident

FieldOfficer

name:StringbadgeNumber:Integer

Dispatcher

name:StringbadgeNumber:Integer

author

incidentsGeneratedreportsGenerated

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

Page 9: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

report_1291 incident_1515bob: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.

Page 10: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

IncidentFieldOfficer

name:StringbadgeNumber:Integer

Allocates

role:StringnotificationTime:Time

resources

incident

1

1..*

Figure 2-24. An example of an association class (UML class diagram).

Page 11: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

Incident

FieldOfficer

name:StringbadgeNumber:Integer

Allocation

role:StringnotificationTime:Time

resources

incident 1

1..*

11

Figure 2-25. Alternative model for Allocation (UML class diagram).

Page 12: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

* *

PoliceStation

*

*

1

1

1

1State

Directory

County

PoliceOfficer

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.

Page 13: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

EmergencyReport Incident

FieldOfficer Dispatcherauthor

initiator

reportsGenerated incidents

1

*

1*

1..*

1

PoliceOfficer

name:StringbadgeNumber: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.

Page 14: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

EmergencyReport Incidentreports1..*

1

{ordered by time of receipt}

Figure 2-44. An example of constraint (UML class diagram).

Page 15: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

Incident

assignResource(r)close()

Figure 2-28. Examples of operations provided by the Incident class (UML class diagram).

Page 16: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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.

Page 17: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

17

c. A file is an ordinary file or a directory file. Generalization. The word “or” often is anindicator 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 relationshipmay 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 composedof” 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.

Page 18: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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

Page 19: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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.

Page 20: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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.

Page 21: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

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.

Page 22: CH-4 Advanced class modeling. BookChapter N composed-of Booch BookChapter composed-of UML 1* Figure 2-7. Example of describing a model with two different

4.11