Monday, September 10, 2018

Superclasses and Subclasses Are Concepts, Not Just Language Features

In some languages, the concept of a class and a superclass are explicit and the relationships between them are explicit. In other languages, superclasses can be declared but the relationship between subclass and superclass is implied. In some languages, even the abstraction itself is implied.

Yet the superclasses and relationships are always present, when relevant; even if only in our minds.

Let's start with the obvious case. Java, C#, C++, Swift and other, similar languages all encourage or even require declaring the abstractions and relationships. So, in these languages, the presence of super- and subclasses is easy to detect and visualize.

Two Subclasses and Their Superclass
Two Subclasses and Their Superclass
In some languages, the super-classes and sub-classes are both defined but the relationship between them is implicit or inferred. Go interfaces are an example of a language structure that works like this. It may not be as easy or obvious to tell if a type implements an interface but the relationship is still there.
Two Subclasses Linked to Their Superclass Implicitly
Two Subclasses Linked to Their Superclass Implicitly
Then there are languages where the superclass, itself, might even be implied. These include so-called "duck typed" languages like JavaScript. Even the concept of a class is kind of flexible in JavaScript.

Yet classification of objects and creating ways of reusing alternatives is still necessary in order to write JavaScript code with any longevity or maintainability. You just have to do a little more of the work to detect what the super-classes are.

Two Subclasses with an Implicit Superclass
Two Subclasses with an Implicit Superclass

Then there are languages like C, where the concept of a class, itself, is missing from the syntax. In this case you have to do all the work to visualize the entities, their relationships, and their categories of interchangeability.

An Implied Set of Classes that Share an Implied Superclass
An Implied Set of Classes that Share an Implied Superclass

...but those things are still there.

The reason for this is because these structures exist in our minds. They are tools for how we think about problems, organize solutions, and connect pieces. The corresponding syntax elements are just ways to make it easier for us to write down that information.

Such features can make it easier for someone to learn or relearn what a design means. They can check for internal inconsistencies in how we express these ideas. In general, they make object-oriented design easier but they aren't what makes it possible for you.

Your mind does that.