Challenge The Premise of The Problem
While at first glance it may seem obvious that a Circle is-an Ellipse, consider the following alternate representation of essentially the same problem, stated in terms of Java code.
class Person { void walkNorth( int meters ) {...} // No failure or exception allowed void walkEast( int meters ) {...} // No failure or exception allowed }Now, a prisoner is obviously a person. So we could logically create a sub-class:
class Prisoner extends Person { void walkNorth( int meters ) {...} // No failure or exception allowed void walkEast( int meters ) {...} // No failure or exception allowed }Just as obviously, this leads us into trouble, since a prisoner is not free to move an arbitrary distance in any direction, yet the contract of the Person
class states that a Person can.
So, in fact, the class Person
could better be named FreePerson
. If that were the case, then the idea that class Prisoner extends FreePerson
is clearly wrong.
By analogy, then, a Circle, is not an Ellipse, because it lacks the same degrees of freedom as an Ellipse.
This strongly suggests that inheritance should never be used when the sub-class restricts the freedom implicit in the base class, but should only be used when the sub-class adds extra detail to the concept represented by the base class as in 'Monkey' is-a 'Animal'.
Read more about this topic: Circle-ellipse Problem, Possible Solutions
Famous quotes containing the words challenge the, challenge, premise and/or problem:
“She might have been old once and now, miraculously, young againbut with the memory of that other life intact. She seemed to know the world down there in the dark hall and beyond for what it was. Yet knowing, she still longed to leave this safe, sunlit place at the top of the house for the challenge there.”
—Paule Marshall (b. 1929)
“She might have been old once and now, miraculously, young againbut with the memory of that other life intact. She seemed to know the world down there in the dark hall and beyond for what it was. Yet knowing, she still longed to leave this safe, sunlit place at the top of the house for the challenge there.”
—Paule Marshall (b. 1929)
“We have to give ourselvesmen in particularpermission to really be with and get to know our children. The premise is that taking care of kids can be a pain in the ass, and it is frustrating and agonizing, but also gratifying and enjoyable. When a little kid says, I love you, Daddy, or cries and you comfort her or him, life becomes a richer experience.”
—Anonymous Father. Ourselves and Our Children, by Boston Womens Health Book Collective, ch. 3 (1978)
“The great problem of American life [is] the riddle of authority: the difficulty of finding a way, within a liberal and individualistic social order, of living in harmonious and consecrated submission to something larger than oneself.... A yearning for self-transcendence and submission to authority [is] as deeply rooted as the lure of individual liberation.”
—Wilfred M. McClay, educator, author. The Masterless: Self and Society in Modern America, p. 4, University of North Carolina Press (1994)