UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory UML Weekend Crash Course™ - To Parent Directory

crnarupa.singidunum.ac.rs
from crnarupa.singidunum.ac.rs More from this publisher
01.01.2015 Views

Session 10—The Class Diagram: Associations 111 Customer 0..* orders 0..* Product Order - quantity: integer = 0 - orderdate: Date = today - terms: Terms = null Figure 10-6 Association class notation Tip Be on the lookout for association classes when you see a multiplicity of more than one on both ends of the association. You don’t always need an association class on these many-to-many associations, but it is a common place to find them. Reflexive association Reflexive association is a fancy expression that says objects in the same class can be related to one another. The entire association notation you’ve learned so far remains exactly the same, except that both ends of the association line point to the same class. This is where the reflexive association gets its name. The association line leaves a class and reflects back onto the same class. Both examples in Figure 10-7 are equivalent expressions. The only difference is that one uses roles and the other uses an association name. Using role names Using an association name 0..1 supervisor Employee 0..* subordinate 0..1 Employee 0..* supervises Figure 10-7 Two ways to model a reflexive association A reflexive association is a very common way to express hierarchies. The example in Figure 10-7 models a hierarchical reporting structure. I could use the same technique for companies owned by other companies. Qualified association Qualified associations provide approximately the same functionality as indexes, but the notation has a bit of a twist. To indicate that a customer can look up an order using the order’s ordernumber attribute, place the ordernumber attribute name and data type in a rectangular box on the Customer end of the association. The rest of the association notation remains intact but is pushed out to the edge of the rectangle.

112 Saturday Morning The placement of the qualifier is sometimes confusing. The best way I have found to remember it is to think of it like this (refer to Figure 10-8): “The Customer uses the ordernbr to look up an Order.” or “One type of object uses the qualifier to access the other (qualified) type of object.” The qualifier goes next to the class of objects that will use the value to do the look up. It is not exactly intuitive but it works. Without a qualifier Customer 1..1 places 0..* Order With a qualifier Customer Figure 10-8 places ordernbr: integer 1..1 1..1 Qualified association Order - ordernbr: integer - quantity: integer = 0 - orderdate: Date = today Tip Typically the qualifier is an attribute of the class on the opposite end of the association, so make certain that the two names and data types agree. Use qualifiers to reduce the multiplicity in the same way you would use indexes in a database to reduce the search time for a specific row or subset of rows. For example, in Figure 10-8, note how the multiplicity for the Order end of the association changed from 0..* to 1..1. This is because the qualifier provided a unique key for Order objects. Before the qualifier was established, navigation across the association would result in a list of all orders associated with that Customer, because the Customer relationship was the only reference available to select the Orders. REVIEW Associations define how objects will be allowed to work together. An association is named to describe the purpose of the relationship. Role names may be used with or in place of the association name to describe how the objects participate in the relationship.

112<br />

Saturday Morning<br />

The placement of the qualifier is sometimes confusing. The best way I have found to<br />

remember it is to think of it like this (refer to Figure 10-8):<br />

“The Customer uses the ordernbr to look up an Order.”<br />

or<br />

“One type of object uses the qualifier to access the other (qualified) type of<br />

object.”<br />

The qualifier goes next to the class of objects that will use the value to do the look up. It<br />

is not exactly intuitive but it works.<br />

Without a qualifier<br />

Customer<br />

1..1<br />

places<br />

0..*<br />

Order<br />

With a qualifier<br />

Customer<br />

Figure 10-8<br />

places<br />

ordernbr: integer<br />

1..1 1..1<br />

Qualified association<br />

Order<br />

- ordernbr: integer<br />

- quantity: integer = 0<br />

- orderdate: Date = today<br />

Tip<br />

Typically the qualifier is an attribute of the class on the opposite end of the<br />

association, so make certain that the two names and data types agree.<br />

Use qualifiers to reduce the multiplicity in the same way you would use indexes in a<br />

database to reduce the search time for a specific row or subset of rows. For example, in<br />

Figure 10-8, note how the multiplicity for the Order end of the association changed from<br />

0..* to 1..1. This is because the qualifier provided a unique key for Order objects. Before the<br />

qualifier was established, navigation across the association would result in a list of all<br />

orders associated with that Customer, because the Customer relationship was the only reference<br />

available to select the Orders.<br />

REVIEW<br />

Associations define how objects will be allowed to work together.<br />

An association is named to describe the purpose of the relationship.<br />

Role names may be used with or in place of the association name to describe how<br />

the objects participate in the relationship.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!