algorithms.us - Blake McBride - Arahant.com
     
fader
 
table-top
  - Company
  - Software Projects
  - Philosophy Interest
  - GO Links
  - Contact
  - Home Page
table-botm
 
Software Projects
: Dynace
: Extension to C

Sample Class Definition

The following code is an example of how a Dynace class and a single method are defined in Dynace:

defclass  MyClass : Super1, Super2 {
        char    name[30];
        int     age;
  class:
        int     numberOfPeople;
};

imeth   int     GetAge()
{
        return age;
}
In this example the new class being created is named MyClass, has two superclasses named Super1 and Super2, has two instance variables named name and age, and one class variable named numberOfPeople. A method used to access the age field is also created and called GetAge. This entire definition resides in a single source (.c) file.

Instance variables are data elements which uniquely exist for each instance of the class which is created. There is only one copy of the class variables, and these variables are common to all instances of the class.

The GetAge method is bound to the MyClass class since they are declared in the same file. Note that neither the GetAge method nor the elements of the MyClass class are accessible to anything outside this source file. Dynace automatically creates a globally accessible object called MyClass for use in creating instances of the class or subclassing it. Dynace also creates a globally accessible function (called a generic) named gGetAge. This generic is common to all classes which have GetAge methods, and performs the dynamic dispatching.


[ Back to Top ]
 


Company | Software Projects | Philosophy Interest
GO Links | Contact | Home Page


Site Content ©2006 Blake McBride.
All Rights Reserved.


.

.