Cardinality

The last issue to visit in this chapter is cardinality. Basically, cardinality pertains to the range of objects that correspond to the class. Using the earlier computer example, we can say that a computer is made up of one, and only one, motherboard. This cardinality is represented as 1. There is no way that a computer can be without a motherboard and, in PCs today, no computer has more than one. On the other hand, a computer must have at least one RAM chip, but it may have as many chips as the machine can hold. Thus, we can represent the cardinality as 1 . . . n, where n represents an unlimited value—at least in the general sense.

Consider the example shown in Figure 9.7 from Chapter 9.

In this example, we have several representations of cardinality. First, the Employee class has an association with the Spouse class. Based on conventional rules, an employee can have either no spouses or one spouse (at least in our culture, an employee cannot have more than one spouse). Thus, the cardinality of this association is represented as 0 . . . 1.

The association between the Employee class and the Child class is somewhat different in that an employee has no theoretical limits to the number of children that the employee can have. Although it is true that an employee might have no children, if the employee does have children, no upper limit exists. Thus, the cardinality of this association is represented as 0 . . . n, and n means that there is no upper limit to the number of children that the system can handle.

The relationship between the Employee class and the Division class states that each employee can be associated with one, and only one, division. A simple 1 represents this association. The placement of the cardinality indicator is tricky, but it’s a very important part of the object model.

The last cardinality association we will discuss is the association between the Employee class and the JobDescription class. In this system, it is possible for an employee to have an unlimited number of job descriptions. However, unlike the Child class, where there can be zero children, in this system there must be at least one job description per employee. Thus, the cardinality of this association is represented as 1 . . . n. The association involves at least one job description per employee, but possibly more (in this case, an unlimited number).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.112.7