它说,在一本书中 the class Name has the property of last name and first name. Address inherits from Name, and has additional property of street number, street name, city, state, zipcode. 这似乎与其他情况不同 猫继承自动物
the class Name has the property of
last name and first name.Address inherits from Name, and has
additional property of street number,
street name, city, state, zipcode.
这似乎与其他情况不同
猫继承自动物,而猫则是“动物”.
对于良好的对象设计,这是“必须”关系还是强制性的?地址应该继承姓名吗?
更新:因为一些用户要求提供源:
alt text http://img192.imageshack.us/img192/8903/learningrubyp133smaller.png
只有在某些行为得到扩展的强烈而明确的关系时,才应使用继承性.
人们应该支持组合而非继承,因为它允许松散耦合和行为的动态变化.