artefaktur
software engineer &        architecture

 
 
 
 

AAL Classes

| Source Code | Preprocessor | Comments | Literals | Classes | Closures | Functions | Function Types |

The object modell of AAL is a mixture of the Java and the C++ modell

Content of this chapter:

   Class definition
     Simple class definition
     Samples
     Derived Classes
     Fields member
       Instance Field Members
       Static Field Members
     Constructor
       Instance Constructor
       Automatic Instance Constructor Generation
       Automatic Super Instance Constructor Invokation
       Static Class Constructor

 Class definition

 Simple class definition

class ClassName [extends SuperClass] (implements InterfaceName)*
{
  Constructors
  Fields
  Methods
  Operators
}

 Samples

class AClass
{
  private int _ival;
  public AClass(int i) : _ival(i) {}
  public int getIVal() { return _ival; }
}

 Derived Classes

A class can be derives from another class via the 'extends' keyword. If a class has no 'extends' keyword it is automatically derived from the class acdk.lang.Object. Only one super class derivation is allowed. Note: Later a multi derivation feature via keyword 'using' is planned.

 Fields member

 Instance Field Members

Instance field member (not static) are bound to the the instance of a class.
class AClass
{
  // [attributes] Type Name;
  private int _ival;
}
By default the values of the fields are initialized with
  • integer numbers: 0
  • float numbers: 0.0
  • character: 0
  • boolean: false
  • Object references: Nil
Instance field members cannot have initializer:
class AClass 
{
  public int value = 42; // illegal
}
See below  Instance Constructor how to initialize field members via constructors.

 Static Field Members

Static field members are bound to a class. All instances of the class shares the same value of a static field member. The static field member can have an initializer. If no initializer for a static field member is declared the fields will be initialized to its default value (see  Instance Field Members).
class AClass
{
  public static int ival = 42; // static field with initializer
}
AClass cls1 = new AClass();
AClass cls2 = new AClass();
cls1.ival == 42; // -> true
AClass.ival == 42; // -> true // access via class identifier
cls2.ival = 41; 
cls1.ival == 41; // -> true
AClass.ival == 41; // -> true
More sofisticated initialization can be done via a Static Class Constructor.

 Constructor

 Instance Constructor

All support the C++ style constructor initialization:
class AClass 

  public int _avar; 
  protected AClass() 
  : _avar(1) // initialize member with 1
  {
    _avar = 1; // alternative notation
    this._avar = 1; // alternative notation
  } 
  protected AClass(int av) 
  : _avar(av) 
  {
  }
}

class BClass extends AClass
{
  public _ivar;
  public BClass(int iv, int av)
  : AClass(av) // call super constructor
  , _ivar(iv) // initialize own member
  {
  }
}
<h4><a href="#jumptable178"><img border="0" src="./../../../../../../images/arrow_up_stop.gif">&nbsp;</a><a class="jumptarget" name="Automatic Instance Constructor Generation">Automatic Instance Constructor Generation</a></h4>
If an super class has no constructor, Aal provides an
default constructor for this class.
The default constructor has no arguements.
<rs>
class AClass 
{
  public int foo() { return 0; }
}
class BClass extends AClass
{
  public BClass() 
  : AClass() // legal, because Aal generate an default constructor for the AClass
  {
  }
}

 Automatic Super Instance Constructor Invokation

In case the super class provides a default constructor (explicit declared or automatically generated) this constructor will be called from the derived instance constructor if no other constructor of the derived class will be explictelly be called:
class AClass
{
  protected AClass() { acdk.lang.System.out.println("AClass.AClass() called");
}
class BClass extends AClass
{
}
// call the automatic generated Constructor BClass.BClass()
// This BClass.BClass() constructor will call the default
// constructor AClass.AClass()
BClass bcls = new BClass();
output> AClass.AClass() called

 Static Class Constructor

In a class definition also an constructor can be declared which be called at load time. The constructor must have the static attribute and must not have any parameters:
class AClass
{
  static acdk.lang.String stringVal;
  // will be called once at load time
  public static AClass()
  {
    stringVal = "asdf";
  }
}
 
Last modified 2005-05-08 22:33 by SYSTEM By Artefaktur, Ing. Bureau Kommer