Cardinality

 <  Day Day Up  >  

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.

Limited Cardinality Values

If we know that there are slots for six RAM chips, the upper limit number is not unlimited. Thus, the n would be replaced by a 6, and the cardinality would be 1 6.


Consider the example shown in Figure 9.7, from Chapter 9.

In this example, we have several different 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.

Making Design Decisions

When designing software, it is important to be sensitive to the fact that there are many different cultures in the world. Thus, making an assumption such as our assumption that an employee can have only one spouse might not be a good thing. If you intend your system to be used internationally, or even nationally within subcultures, you need to think about the design from many angles.


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, there are no limits to the number of children that the employee might have. 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.

More Design Issues

In certain situations, it is possible for an employee to be associated with more than one division. For example, a college might allow an individual to hold concurrent positions in the mathematics department as well as the computer science department. This is another design issue you must consider.


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

Keeping History

You must also consider that an employee can have job descriptions for past jobs, as well as for current jobs. In this case, there needs to be a way to differentiate current job descriptions from past ones. This could be implemented using inheritance by creating a collection of job objects with an attribute indicating which job is currently active.


 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net