7.7.1 Instantiable classes

A class that can be used as the first argument to make is an instantiable class. All concrete classes are instantiable. When you define an abstract class, Dylan does not provide a method for make that enables you to create direct instances of that class. Thus, if you call make on an abstract class, you get an error.

Even though an abstract class does not have direct instances, it is sometimes possible to use an abstract class as the first argument to make. In this case, the make function creates and returns a direct instance of a concrete subclass of the abstract class. In other words, make can return either a direct or an indirect instance of its first argument.

To make it possible for an abstract class to be provided as the first argument to make, you define the abstract class, and define one or more concrete subclasses of it. You then define a method for make that specializes its first parameter on the abstract class, and that returns an instance of one of its concrete subclasses. To define make methods, you need to use the singleton function to create a type whose only instance is the class itself; see Chapter 9, Nonclass Types. Definition of make methods is an advanced topic that we do not cover in this book.

What is the reason for enabling users to call make on an abstract class? This flexibility allows a program that needs a general kind of object, represented by a superclass, to ask for an instance of the superclass without specifying the direct class of the instance. For example, a program might need to store data in a vector, but might not be concerned about the specific implementation of the vector that it uses. Such a program can create a vector by calling make with the argument <vector>, and make will create an instance of a concrete subclass. The built-in <vector> class is abstract, but is instantiable.