Object-Orientation with XOTcl Components and Object Introspection - Tutorial

In this section you will learn about dynamic and object-oriented aspects of XOTcl programming in XOTclIDE.

Load Sample Application

Start the XotclIDE per

[artur@rybnik xotclIDE]$ ./XotclIDE
Now load the component SampleComponent [1] that is included into XOTclIDE distribution. Choose the menu Component->Load Package in Component Browser. In a dialog-box select "SampleComponent" package to load. Now you should see following state in your Component Browser window.

Figure 7. Sample Component in Component Browser

The Component have two classes (Railroad and Wheel). Try to browse the methods of these classes.

Create an Instance of one Class

Now it is time to create some instance of Railroad class. Select the Railroad class in Class view and choose the menu Class->Create Instance you will see following dialog

Figure 8. Create Instance Dialog

In this dialog you can specify the arguments (or additional arguments) for init method (passed to init method or parameters). The class definition of Railroad is
Class Railroad -parameter {{speed 4}}
You can modify the start speed by specify your speed value (enter "-speed 10"). In this case you can simply push OK button and use default speed.

Object Inspector

The new created object of class Railroad build a window and gets run.

Figure 9. Sample Railway application

Additional XOTclIDE shows an another window called object inspector browser. This window shows the internal structure of XOTcl objects. You can see its variables (attributes), subobjects (aggregated objects) and methods.

You can modify the object state per changing variable. Choose the speed variable. You should see the value 4 in your edit-area view. So type 20 in this area and press Control-S or choose menu Edit->Save Have you noticed that, the rail have speeded up.

Figure 10. Object Inspector

You can also invoke methods on an object directly in Object Inspector. Select emergencyBreak method and choose menu Method->Invoke.

Figure 11. Methods in Object Inspector

You can also specify which method you should see (only from Railroad or also inherited from Object or Superclasses). You can even see the method available per mixin on viewed object.

Notes

[1]

Example by Richard Suchenwirth translated from Tcl to XOTcl by Gustaf Neumann and modified by me. Primary published on tclwiki.