?
继承是is a
的关系,也就是说,可以把子类完全当作一个父类来对待,所以子类必然要响应所有父类的action
,否则违背继承的逻辑。所以,你可能哪里错了。programing ruby 中的一段话:
Now, a lot of research has been done on type theories. One of the more famous results is
the Liskov Substitution Principle. Formally, this states: “Let q(x) be a property provable
about objects x of type T. Then q(y) should be true for objects y of type S where S is a
subtype of T.” What this means is that you should be able to substitute an object of a child
class wherever you use an object of the parent class—the child should honor the parent’s
contract. There’s another way of looking at this: we should be able to say that the child
object is a kind of the parent. We’re used to saying this in English: a car is a vehicle, a cat
is an animal, and so on. This means that a cat should, at the very least, be capable of doing
everything we say that an animal can do.