Mixin classes
Factor handbook > The language > Objects > Classes

Prev:Maybe classes
Next:Predicate classes


An object is an instance of a union class if it is an instance of one of its members. In this respect, mixin classes are identical to union classes. However, mixin classes have the additional property that they are open; new classes can be added to the mixin after the original definition of the mixin.
MIXIN:

INSTANCE:

define-mixin-class ( class -- )

add-mixin-instance ( class mixin -- )


The set of mixin classes is a class:
mixin-class

mixin-class? ( object -- ? )


Mixins are used to defines suites of behavior which are generally useful and can be applied to user-defined classes. For example, the immutable-sequence mixin can be used with user-defined sequences to make them immutable.

See also
Union classes, Maybe classes, Tuple subclassing