Why are Super-class and Sub-class reversed?

后端 未结 7 2299
滥情空心
滥情空心 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:30

    Greg's answer is correct. Here's an explanation by example:

    You have a base class Base. You have two derived classes DerivedA and DerivedB. Every instance of DerivedA is also an instance of Base. Likewise, every DerivedB is also a Base. But, a DerivedA is not a DerivedB and vice versa. So, if you were to draw a Venn diagram of the universe of all possible objects, you'd get:

        ________________________
       /                        \
      /          Base            \
     /    ______        ______    \
    |    /      \      /      \    |
    |   /        \    /        \   |
    |  | DerivedA |  | DerivedB |  |
    |   \        /    \        /   |
    |    \______/      \______/    |
     \                            /
      \                          /
       \________________________/
    

    In other words, every object in the set of DerivedA objects is also in the set of Base objects. Likewise for DerivedB. So Base is indeed the superset of both DerivedA and DerivedB. Hence, it is the "superclass".

    0 讨论(0)
提交回复
热议问题