我注意到,很多时候,我不清楚一个由许多子类组成的超类在属性方面应该更一般还是更受限制。下面是一个人为的例子来说明我的意思:
# A) superclass more general (union of attributes)
class human:
self.__init__(height, beardColor, nailColor):
self.height=height
self.beardColor=beardColor
self.nailColor=nailColor
class man(human):
self.__init__(heigth, beardColor):
super().__init__(height, beardColor, None)
class woman(human):
self.__init__(heigth, nailColor):
super().__init__(height, None, nailcolor)
# B) superclass more specific (intersection of attributes)
class human:
self.__init__(height):
self.height=height
class man(human):
self.__init__(heigth, beardColor):
super().__init__(height)
self.beardColor=beardColor
class woman(human):
self.__init__(heigth, nailColor):
super().__init__(height)
self.nailColor=nailColor
它以某种方式归结为一个问题:一个超类是否应该拥有子类的所有属性的并集,或者更确切地说是它们的交集
他们的研究是否有哪种范式更好的一般规则
目前没有回答
相关问题 更多 >
编程相关推荐