Why are Super-class and Sub-class reversed?

后端 未结 7 2254
滥情空心
滥情空心 2021-02-12 12:29

In set theory, a set is a superset if it contains everything in the original set and possibly more. A subset however is does not contain everything of the initial set.

W

7条回答
  •  有刺的猬
    2021-02-12 13:23

    Greg is correct. Two things to consider that might make it more clear:

    1. the propertes and methods are not relevant to the sub/super relationship in terms of set theory:

      • the properties and methods defined by a subclass may extend beyond those provided by its superclass (and in fact, they often do), but instances of the subclass are still members of the set of instances of the superclass
      • in other words, the sub/super relationship is not defined by the propertes and methods, but by the instance-level semantics intended by the naming of the classes
    2. Taxomony example:

      • the set of all People is larger than the set of all Programmers
      • the set People is, in fact, a superset of the set Programmers
      • the set Programmers is a subset of the set People

    so in OOP terms, People would be a superclass and Programmer would be a subclass. Every Programmer is a person, but not every person is a Programmer. Hence superclass and subclass. The fact that the Programmer class may have super powers beyond the ken of mortal men does not change the class-relationship (is-a) semantics.

提交回复
热议问题