Class That Describes All Classes, Including Itself

A class is a list of properties common to all objects it subsumes. For example, the class "Tree" lists the properties common to all trees, like color or height or age.

But this is also the common property of all classes, making the class of all classes look like this:

class Property {
	Type type;
    String name;
}

class Class {
	List<Property> properties;
}

I.e., all classes (objects of class Class) have the common property of listing properties common to all their respective objects.

The class Tree can then be instantiated like this:

Property color = new Property(type=string, name="color");
Property height = new Property(type=double, name="height");
Property age = new Property(type=double, name="age");

List<Property> properties = new List<Property>();
properties.add(color);
properties.add(height);
properties.add(age);

Class Tree = new Class(properties);

Which is another way to write:

class Tree {
	string color;
    double height;
    double age;
}

The question now is, can you instantiate Class from itself?

The answer is yes:

Property properties = new Property(type=List<Property>, name="properties");
List<Property> _properties = new List<Property>();
_properties.add(properties);

Class class = new Class(properties);

What have we learned?

  1. A class lists properties common to all objects it describes,
  2. Classes themselves can be considered objects with a common property: That they list properties of objects they describe,
  3. Thus a class of all classes is possible, and is defined in that very way,
  4. Such a class must then be able to describe itself (as it itself is a class),
  5. Which it does without a need for modifying the definition above,
  6. Making it an instance of itself as well as its own class at the same time.

Subscribe to RASHAD.IO

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe
DigitalOcean Referral Badge