Chapter 9 . Inheritance


Chapter 9. Inheritance

Exercise 31. Collection Classes

A. The read-only collections throw an exception, so it's an honest refusal.

B. Java doesn't require explicit declaration of all exceptions, and these are of the type that needn't be declared.

C. One alternative would be to let every collection class come in two flavors: one for read-only and one for not. This would lead to a lot of near-duplicate classes. Refused Bequest seems like the lesser evil.


Exercise 33. Swing Libraries

A. The interface expresses the essential information about the object and helps decouple clients from the detailed classes. Furthermore, Java supports multiple inheritance of interfaces, but only single inheritance for classes. By keeping the interface separate, classes can add support for the interface, but keep their original hierarchy otherwise .

B. While the framework has only one implementation of the class, it's expected that users of the framework will introduce other classes, and the abstract class forms a handy root for that. If there were no other classes coming, it's conceivable that you might still decide to split out the abstract class just to make the code communicate better.

C. You probably wouldn't start with this structure, but it represents a possible evolutionary path for your code.




Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

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