Class and Object Composition - Quiz Explanation

The answers you selected are indicated below, along with text that explains the correct answers.
 
1. Consider a Check object and its associated Date object and Money object.
The object is named phoneBill. 
Check number 1023 is for &#3623.12. 
The check was written on July 7, 1998. 
The check was made payable to Bell Atlantic. 
The memo line contains
"June phone bill, 212-555-8767-R123." 
Which of the following is a correct object diagram for this object?
Please select the best answer.
  A. first diagram
  B.
second diagram
  C. third diagram
  D.
fourth diagram
 

The correct answer is A.

Answers B, C, and D are incorrect because the values of the composed objects should not be shown in the Check object. In many cases, it won't even be possible to show them.

2. Which of the following verbs best indicates a composition relationship between two classes?
Please select the best answer.
  A. Needs, as in " a fee calculation needs the interest rate"
  B. Is, as in " a car is a vehicle"
  C. Has, as in " a car has a transmission"
  D. Describes, as in " a priority describes a request"
 

The correct answer is C .

The correct answer is C because " has a" , " uses a," or " owns a" are usually indicators of a composition relationship. A is incorrect because " needs" could indicate an attribute of the class or a collaboration with another class. B is incorrect because an " is a" relationship can simply be that of an object (car) to its own class (vehicle). D is incorrect because " describes" implies an attribute: Priority is probably an ordinary attribute of request in this case.

3. The Money class is likely to be used as an attribute of the Check, Deposit, and CheckingAccount classes. Based on this decision, which one of the following statements is most true?
Please select the best answer.
  A. The same developer who works on the Money class must work on the Check, Deposit, and CheckingAccount classes.
  B. If the rules for Money change, Check, Deposit, and CheckingAccount must also be changed.
  C. The rules for Money need be written only once and can be used throughout the program.
  D. The system will be more vulnerable to bugs because the rules for Money are in only one class.
 

The correct answer is C.

If a rule is changed (or a developer remembers a rule and adds it during development), the change will be made for all three classes at once. There's no way to forget and change the code for only two of the three. A is incorrect because the developers who work on these classes can rely on Money to enforce the rules, so the classes could be given to separate developers. B is incorrect because the new Money class will be used by all three classes without changing any code. D is incorrect because this approach will actually reduce bugs by guaranteeing that all three classes use the same Money rules.