Many programs written with inheritance can be written with composition instead, and vice versa. Rewrite class BasePlusCommissionEmployee of the CommissionEmployee–BasePlusCommissionEmployee hierarchy to use composition rather than inheritance. After you do this, assess the relative merits of the two approaches for designing classes CommissionEmployee and BasePlusCommissionEmployee, as well as for object-oriented programs in general. Which approach is more natural? Why?
What will be an ideal response?
For a relatively short program like this one, either approach is acceptable. Inheritance becomes preferable when it makes the program easier to modify and promotes the reuse of code. The inheritance approach is more natural because a base-salaried commission employee is a commission employee. Composition is defined by the “has-a” relationship, and clearly it would be strange to say that “a base-salaried commission
employee has a commission employee.”
You might also like to view...
Holding down the ____ key while dragging an oval shape creates a perfect circle.
A. SHIFT B. ESC C. OPTION D. F2
As public-key cryptography is computationally intensive and drains the battery of Barack's device, he comes up with an alternative approach. First, he shares a secret key k with Hillary but not with Bill. Next, together with a joke x, he sends over the value d = h(k||x), where h is a cryptographic hash function. Does value d provide assurance to Hillary that Barack is the author of x and that x
was not modified by Bill? Justify your answer. What will be an ideal response?
Articles of Incorporation can be printed on both sides of the paper.
Answer the following statement true (T) or false (F)
Which of the following should Matt, an administrator, implement in a server room to help prevent static electricity?
A. GFI electrical outlets B. Humidity controls C. ESD straps D. EMI shielding