Open GENIE is built with an underlying "Object Oriented" programming system. This system is used in several places within Open GENIE internally, for example, to allow the re-definition of workspace operations like "+", "-", "*" and "/".
For more sophisticated data analysis and treatment programs, this underlying object structure can be used to produce fully object oriented and very flexible data models (or formats). The NeXus data model within Open GENIE is implemented in this way.
There are two functions which allow the creation, first of data "types" or "classes" and instances of these classes, respectively these are the Subclass() and Create() methods.
The other key requirement is to be able to associate "methods" with these classes. To do this, the Add_method() procedure allows you to seamlessly associate a class method with a pre-written Open GENIE procedure.
Examination of a class hierarchy can be using the Hierarchy() function whilst the details of individual objects can be printed with Printn() just like any other variable.
Add_method | Print the current working directory |
Create() | Create a specific instance of the specified class |
Hierarchy | Prints out the class hierarchy given a starting class |
Subclass() | Define a brand new subclass or specialisation of an existing data type. |
This example demonstrates how to set up a very simple class hierarchy and how methods can be inherited or specialised within Open GENIE. To run the example, put the subclass and procedure definitions into a GCL file then load them up before typing the rest of the example at the command line. To understand the example, pay close attention to what happens and which functions are being executed on which workspace object. Notice how things change once a specialised method is added to the second class and how it is possible to both refer to the object itself as "_self" and to call the superclass method by appending an underscore to access the superclass function.
Subclass class="Triple_axis" superclass="Structure" & comment="TA class comment" names="f1 f2 f3" Subclass class="My_Triple_axis" superclass="Triple_axis" & comment="My TA class comment" names="f4" PROCEDURE ta_focus PARAMETERS a b c LOCAL test printn "ta_focus" a b c printin _self ENDPROCEDURE PROCEDURE my_ta_focus PARAMETERS self=my_triple_axis [_self._focus()] # Call the parent focus on ourself printn "My focus" printdn _self ENDPROCEDURE
>> add_method "triple_axis" "ta_focus" "focus" >> a = create("triple_axis") >> b = create("my_triple_axis") >> [ a.focus() ] ta_focus Triple_axis [TA class comment] ( f2 = _ f3 = _ f1 = _ ) >> [ b.focus() ] # Calling focus in superclass ta_focus My_triple_axis [My TA class comment] ( f2 = _ f4 = _ f3 = _ f1 = _ ) >> add_method "my_triple_axis" "my_ta_focus" "focus" # now add a specilised method >> [ b.focus() ] # Calling its own focus ta_focus My focus My_triple_axis [My TA class comment] ( f2 = _ f4 = _ f3 = _ f1 = _ ) My_triple_axis [My TA class comment] ( f2 = _ f4 = _ f3 = _ f1 = _ )