Skip to content

Latest commit

 

History

History
99 lines (88 loc) · 3.13 KB

instantiable-type.md

File metadata and controls

99 lines (88 loc) · 3.13 KB

Instantiable Type

An instantiable type is a type that the end-user can create objects from. This includes:

For example:

For example:

// `ValueObject` is a base class.
class ValueObject<T> {
    protected value T;

    protected constructor(input: T) {
        this.value = T;
    }

    public valueOf(): T {
        return this.value;
    }
}

// the end-user can't create new objects of type `ValueObject`
// they cannot instantiate this type
const myValue1 = new ValueObject("not allowed!");

// `MediaType` is a child class
class MediaType extends ValueObject<string> {
    public constructor(input: string) {
        mustBeMediaTypeData(input);
        super(input);
    }
}

// the end-user can create new objects of type `MediaType`
// they CAN instantiate this type
const myValue2 = new MediaType("text/html; charset=UTF-8");