Problem

Is-a, Has-a, and Notions of InheritanceSometimes is-a doesn’t help to determine when inher...

Is-a, Has-a, and Notions of Inheritance

Sometimes is-a doesn’t help to determine when inheritance is the right idea. In English, is-a can mean specificity in the sense of more detail (inheritance) or it can mean specificity in terms of less detail (a special case).

For example, when we say a manager is a kind of employee, we mean that a manager has everything an employee has and more. In this sense, a manager extends or generalizes the notion of an employee, even though it is a special case of an employee. But when we say that every integer is a fraction, we do not mean that an integer extends or generalizes the concept of a fraction. We mean that an integer is a special case of a fraction and, if anything, a fraction has everything an integer has and more. Manager naturally extends employee, but integer does not naturally extend fraction.

a. In general, if A is-a B, then which class is more specific and which is more general?


b. When a class is more specific, does it have more instance variables and methods, or fewer? Explain.


c. Is a square a kind of cube, vice versa, or neither? Is a square a kind of rectangle, vice versa, or neither? Among the classes Cube, Square, and Rectangle, which might inherit from which and why? Explain your reasoning in light of (a) and (b).

That is, what extra instance variables or methods would apply to your more specific classes in any inheritance hierarchy you propose?


d. Is a point a kind of circle, vice versa, or neither? Is a circle a kind of cylinder, vice versa, or neither? Among the classes Point, Circle, and Cylinder, which might inherit from which and why? Explain your reasoning in light of (a) and (b). That is, what extra instance variables or methods would apply to your more specific classes in any inheritance hierarchy you propose?


e. “Favor composition over inheritance” is a maxim of object-oriented design. Go back to problems (c) and (d) and discuss whether any of those classes might be built naturally out of the others via composition rather than inheritance. Give details.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 12
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT