Building Metamodels for Edge Classes

In Edge.gm you define your edge classes and their attributes. Edge classes need to be separated into directed (relation only works in one way, e.g. IsFatherOf) and undirected (relation works in both directions, e.g. HasRelative) edge classes.

Just like node classes edge classes can either be defined as abstract or concrete. 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) Edge Class

A new edge class is defined as shown below. The names (IsFamilyOf,IsRelative) are freely chosen. At least one class (concrete or abstract) needs to extend the general top-level directed/undirected edge class IdentifiableDirectedEdge/IdentifiableUndirectedEdge.

directed edge class IsFamilyOf extends IdentifiableDirectedEdge;
undirected edge class IsRelative extends IdentifiableUndirectedEdge;

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. Possible data types are listed hereDefault attribute values can also be defined as shown below. There is no limit to the number of attributes per class.

directed edge class IsFamilyOf extends IdentifiableDirectedEdge{
   quantity:int;     //instead of int any other primitive data type can be used
   //add more attributes here if wanted 
}

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

node class IsSonOf extends IsFamilyOf{
}

Defining an Abstract Edge Class

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

abstract directed edge class IsFamilyOf extends IdentifiableDirectedEdge;

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

Example

Your edge metamodel may look like this in the end:

abstract directed edge class IsFamilyOf extends IdentifiableDirectedEdge{
    name:string;
    id:int;
    quantity:int=1;
 }

directed edge class IsSonOf extends IsFamilyOf;

abstract undirected edge class IsRelative extends IdentifiableUndirectedEdge{
    id:int;
 }

undirected edge class IsCousin extends IsRelative{
    name:string;
 }

undirected edge class IsSibling extends IsRelative;

Was this article helpful?

Related Articles