XES - Programmers Guide - nodeClass

The ClassDef node is used to define a class or interface.

It is also used to instatiate a class. (see issues below)

A ClassDef can occur in a package node or inside another class (inner class) or anywhere where a class can be instantiated.

Attributes used

Child Elements

If this class extends another class or implements interfaces then these should be defined in nameList node or nodes. If there are any nameList nodes then they should be before any other child nodes (apart possibly from comment nodes)

Other possible child elements of classDef are:

Issues

How should class instantiation be handled? For instance:
myClass c=new myClass();

Should this be coded in XES by using a 'classDef' or a 'call' node? The argument for using 'classDef' is that the same node type is used to define and use the class, the argument for using a call node is that it involves calling the constuctor so it has arguments similar to a method call.

I think it is best to use a 'classDef' to instantiate a class because this allows anonymous inner classes - where a class is defined and instantiated at the same point in the program. This makes the handling of class to be similar to variable in that they are both used to define and initialise the quantity.

However the 'call' node is still used for explicit constructor invocation such as this() or super()

Note array instantiation such as:

new int[1];

or

new myArray[4];

is handled by array node and not classDef node.

Another Issue

Can the 'classDef' which instantiates a class be linked to the 'classDef' which defines the class in a more direct way than using its name? Perhaps the instantiating node could have an XPath field or somthing like that, this would allow the definition to be found more quickly. In an object oriented program the definition may only be found at runtime, but perhaps we could link to the base class or at least to something to speed up finding the class defintion.

Schema entry

<xs:complexType name="classType">
<xs:sequence>
<xs:element name="method" type="methodType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="classDef" type="classType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variable" type="variableType"/>
<xs:element name="tags" type="tagList"/>
<xs:element name="meta" type="xs:string"/>
<xs:element name="comment" type="commentType"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="implements" type="xs:string"/>
<xs:attribute name="extends" type="xs:string"/>
<xs:attribute name="public" type="xs:boolean"/>
<xs:attribute name="private" type="xs:boolean"/>
<xs:attribute name="protected" type="xs:boolean"/>
<xs:attribute name="static" type="xs:boolean"/>
<xs:attribute name="abstract" type="xs:boolean"/>
<xs:attribute name="interface" type="xs:boolean"/>
</xs:complexType>

Possible Improvements

 

Examples of usage

usage java example XES example
class definition class myClass {
}
<class def="true" name="myClass"/>
class instantiation myClass c=new myClass();

<variable name="c" type="myClass">
<assign operator="=">
<variable>
<class name="myClass" new="true"/>
</variable>
</assign>
</variable>

class instantiation with parameters for constructor myClass c=new myClass(int a,double b); <variable name="c" type="myClass">
<assign operator="=">
<variable>
<class name="myClass" new="true">
<variable name="a"/>
<constant intConst="2"/>
</class>
</variable>
</assign>
</variable>
public modifier public class myClass {
}
<class def="true" name="myClass" public="true"/>
protected modifier protected class myClass {
}
<class def="true" name="myClass" protected="true"/>
private modifier private class myClass {
}
<class def="true" name="myClass" private="true"/>
abstract modifier abstract class myClass {
}
<class abstract="true" def="true" name="myClass"/>
static modifier static class myClass {
}
<classDef name="myClass" static="true"/>
final modifier final class myClass {
}
<classDef final="true" name="myClass"/>
synchronized modifier synchronized class myClass {
}
<class def="true" name="myClass" synchronized="true"/>
native modifier native class myClass {
}
<class def="true" name="myClass" native="true"/>
extending a class class myClass extends baseClass{
}

<class def="true" name="myClass">
<nameList elementName="extends" type="baseClass"/>
</class>

implementing an interface class myClass implements baseInterface{
}
<class def="true" name="myClass">
<nameList elementName="implements" type="baseInterface,baseInterface2"/>
</class>
extend and implement class myClass extends baseClass implements baseInterface{} <class def="true" name="myClass">
<nameList elementName="extends" type="baseClass"/>
<nameList elementName="implements" type="baseInterface"/>
</class>
defining an interface interface myInterface{
}
<class def="true" interface="true" name="myInterface"/>
nested classes (inner class) class myClass {
class nestedClass {
}
}
<class def="true" name="myClass">
<class def="true" name="nestedClass"/>
</class>
anonymous inner classes class myClass {
void myOuterMethod() {
new myAnonymousClass() {
public void myInnerMethod(){
}
};
}
<class def="true" name="myClass">
<method name="myOuterMethod" type="void">
<parameterList/>
<variable>
<class def="true" name="myAnonymousClass" new="true">
<method name="myInnerMethod" public="true" type="void">
<parameterList/>
</method>
</class>
</variable>
</method>
</class>
     

Mapping to other languages

Modifiers

XES java C# C++
  public public  
  protected protected  
  private private  
  abstract abstract  
  static    
  final    
  strictfp    
    new  
    internal  
    sealed  
    unsafe  
  interface    
  native,synchronized,transient,volatile    

Java

class myClass{
  public myClass(int n) {...} // constructor same name as class
   ...
} 

interface myInterface{
   ...
}

Scala

Scala allows class and object definitions, object defines the class and instantiates it, similar to static classes in java. Scala can have parameters, here the return type is inferred.

class myClass(n: int){ // primary constructor parameters in brackets
  def a(): int =1 // parameter
  def b: int=2 // parameter can be defined without brackets
   ...  
} 

or object which instantiates class as well as defining it.

object myClass(n: int){ // primary constructor parameters in brackets

 ... 
} 

trait is an abstract class like java interface but can also contain method implementations

case classes

abstract class Tree
case class Sum(l: Tree, r: Tree) extends Tree
case class Var(n: String) extends Tree
case class Const(v: int) extends Tree

 

.

metadata block
see also:

 

Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.