This section contains 396 words (approx. 2 pages at 300 words per page) |
A base class (also called superclass or parent class) is a term from object-oriented design that denotes a class that another class extends--other classes are based on it. In other words, if class B is based on class A, then class A is said to be the base class of class B. Programmatically this might look something like this in C++:
- class Haircut {}; // "base class" or "superclass"
- class Mohawk : public Haircut {};
and like this in Java:
- class Haircut {}; // "base class" or "superclass"
- class Mohawk extends Haircut {};
If Mohawk were to be extended once more by deriving another class from it, then it might look like this:
- class ColouredMohawk : public Mohawk {} // in C++
or
- class ColouredMohawk extends Mohawk {} // in Java
In each of these cases Mohawk becomes the base class of ColouredMohawk.
The opposite of a base class is a "derived class" (or "subclass"). Thus, if Haircut is the base class of Mohawk, then Mohawk is a derived class of Haircut.
The relationship between a derived class and its base class is sometimes called a "kind of" relationship, where the derived class is a "kind of" its base class. Using the examples above it is easy to see that a Mohawk is a "kind of" haircut, but the reverse is rather nonsensical (a haircut is not a "kind of" Mohawk).
When classes are arranged like this in terms of base class" and derived class it is called a "class hierarchy," with the more general classes, like Haircut, at the top and the more specific classes, like ColouredMohawk at the bottom.
Derived classes typically "inherit" the data and functionality of their superclasses (though exactly how depends on the language used) and then add more functionality and data of their own to fulfil their own requirements. In general a derived class is more complex and specific in terms of functionality and the data it comprises than its base class.
There is sometimes a subtle difference in meaning between the expressions "base class" and "superclass." The expression "base class" can be used to denote the very topmost class of the hierarchy as well as a base class of a specific class, whereas the expression "superclass" is generally used as a more relative term to mean "the base class of this class"; however, the terms are almost completely interchangeable and only a purist would worry about the differences.
This section contains 396 words (approx. 2 pages at 300 words per page) |