Search code examples
language-agnosticoopprogramming-languages

Why are Super-class and Sub-class reversed?


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.

With that in mind, in most object-oriented programming languages (I'm thinking Objective-C but I know the same is true for Java and others), the parent class is called the super class, and any class which inherits from the super is called a subclass.

Isn't this backwards? A subclass inherits things like all instance variables and methods from its superclass, thus it "contains" everything from the parent, plus whatever is added in the subclass. Is this just a naming mistake or was this intentional, and if so why?


Solution

  • A superclass defines a class that has a larger set of possible values as members. A subclass restricts the items that can be part of its class, so it defines a smaller set of possible members.

    The set of possible members of a superclass is a superset of the set of possible members of a subclass of that superclass.