The concept of a class is fundamental in object-oriented programming. Objects instantiate (or are classified by) a class. A class defines the properties and methods for the objetcs that instantiate it.
In the form of a constructor function that allows to create new instances of
the class with the help of the
new operator. This is the classical approach
In the form of a factory object that uses the predefined
Object.create method for creating new instances of the class.
Since we normally need to define class hierarchies, and not just single classes, these two alternative approaches cannot be mixed within a class hierarchy, and we have to make a choice whenever we build an app. With mODELcLASSjs, you choose the second approach with the following benefits:
Properties are declared (with a property label, a range and many other constraints)
Supports object pools
Supports multiple inheritance and multiple classification
These benefits come with a price: objects are created with lower performance, mainly due to
the fact that
Object.create is slower than
new. On the other
hand, for apps with lots of object creation and destruction, such as games and
simulations, mODELcLASSjs provides object pools for avoiding performance problems due to
The properties and methods of the meta-class mODELcLASS are listed in the following class diagram:
Notice that in the class diagram, we use the type
oBJECT for values
with mODELcLASS. These objects have a pre-defined property
the model class they instantiate as their direct type. The values of the pre-defined
instances are maps of
oBJECTs representing the
extension (or population) of a model class.