Building Metamodels for Node Classes

In Node.gm you define your node classes and their attributes. A node class can either be defined as abstract or concrete node class. Inheritance allows you to define subclasses which extend superclasses. The subclasses inherit all attributes of their superclass. Multiple levels of inheritance are possible.

Defining a (Concrete) Node Class

A new node class is defined as shown below. The name NodeClass1 is freely chosen. At least one node class (concrete or abstract) needs to extend the general top-level node class IdentifiableNode.

node class Part extends IdentifiableNode;

To define attributes of a class use curly brackets after the class definition, write one attribute name per line (freely chosen) and define the data type of the attribute. Data types can be primitive data types or container types. Default attribute values can also be defined as shown below. There is no limit to the number of attributes per class.

node class Part extends IdentifiableNode {
   id:int;       
   quantity:int = 1; //instead of int any other primitive data type can be used
   name:string;
   //add more attributes here if wanted
}

To extend a node class and build a class hierarchy that uses inheritance just let one node class (e.g. Part) extend another node class (e.g. BomNode), as shown below. Remember that in the given example Part will also inherit the attributes of BomNode:

node class BomNode extends IdentifiableNode{
   id:int;
   name:string;
}

node class Part extends BomNode{
   quantity:int=1;
}

Defining an Abstract Node Class

You may want to create node classes that are not needed for modeling (i.e. you do not want to create instances of these classes) but only for inheritance. Defining a node class as abstract does the trick. To define an abstract node class simply type the keyword abstract before the class definition as shown below.

abstract node class BomNode extends IdentifiableNode;

Abstract node classes can have attributes, too. Multiple abstract node classes can exist. Abstract node classes can extend abstract node classes. Concrete node classes can extend abstract node classes.

Example

Your node metamodel may look like this in the end:

abstract node class BomNode extends IdentifiableNode{
   name:string;
   id:int;
}

node class Part extends BomNode{
   quantity:int = 1;
   parentid:int;
}

node class MergedPart extends Part{
}

Was this article helpful?

Related Articles