Discussion Questions for Riel, Sections 5.1-5.10
Protected and Private Inheritance
-
What are some examples of when private inheritance and protected
inheritance in C++ are useful and how can these implemented relationships
"be used to implement containment?" (85) (Mike C)
-
If protected and private inheritance serve no purpose, why were they
included in the C++ specification? Perhaps if used in a limited scope,
along with the friend keyword, they can be used to exploit polymorphic
behavior while maintaining tighter encapsulation than would be possible in
a design without private inheritance. (John)
-
Can you outline the advantages of a protected section? (Monica)
-
I'm still a little confused about the difference between private and
protected objects and methods, could you give us a real world example of a
class design that would necessarily involve both? (Dave V)
-
Why does Riel discourage from using private and protected
inheritance?(Gaurav)
-
In heuristic 5.3, Riel implies that protected data type should only be used
for an interface of base class. How does the protected interface is easier
to maintain than declaring a a public field? (Chayapan)
-
The book talks about Private, Protected, and Public Inheritance in
C++. Would you talk about them in Java, please emphasize the difference?
Inheritance and Polymorphism
-
Do subclasses have to implement all superclass methods? For example, if a
subclass overrode a method so that it did nothing, would this be proper
object oriented design? (Mike L.)
-
If there are three classes A, B and C, A has f1() and f2() methods; B
inherits A and has overriding method f2(), then if C inherits B, does C
have the same f2() as B or A? (Sheng)
-
In the LinkedList example in section 5.10, doesn?t changing the base class
(LinkedList) to accommodate LinkedRing imply adding unnecessary data for
SortedLinkedList? (Chayapan)
-
How useful is implementing true polymorphism and what are its advantages
and disadvantages? Does it always use strings and hash tables? (Mike C)
Design Issues
-
What are the pros and cons of combining heuristic 5.9 and 5.10? In other
words, why is it not a good practice to put the common data used by two or
more classes (from heuristic 5.9) in a separate class that will be
inherited by classes using that data? Why do we instead use just an
instance as opposed to inheritance process for a case where one has to use
the common data only (and not common method)? (Saugar)
-
Pure polymorphic classes contain no data, just implementation. They also
can?t be instantiated. An earlier heuristic stated that classes should be
tightly coupled collections of functions and data. Was Riel not
considering pure polymorphic classes when he wrote this heuristic? (John)
-
What is the significance of heuristic 5.4 when its paradox, heuristic 5.5,
says that in practice, inheritance hierarchies should not really be deep?
(Saugar)
-
I understand the notion of why it's desireable in large programs to have
very deep hierarchyies of inheritance, but if you just have a small program
is there any advantage to deep inheritance? Let's say if there's only 2
objects and each of them can have a hierarchy listing of of order 12...why
would you ever do that if you don't have to? (Dave V)
-
Why should the depth of inheritance hierarchies be limited in practice?
(Gaurav)
-
Isn't Heuristic 5.4 sort of pointless and also, a bad theory? Why is it
mentioned as a separate Heuristic if he later says not to have the hierachy
deeper than your short-term memory and proves the theory to be wrong?
(David D)
-
How do you know if the inheritance hierarchy is wide enough? (Mike L.)
Language Issues
-
Can you explain the overriding method (monica)
Other Questions
-
Does Murphy's 79th law of programming actually exist? If so, is it a book
or what? (David D)
This document is available on the World Wide Web as
http://www.cs.grinnell.edu/~walker/courses/223.sp05/readings/riel-5a.shtml