Activity Status Class


The idea of object-orientation is not new to JSL, but user-created objects require a complex code structure that wraps data and functions into namespaces (for example, see the navigation wizard).

In version 14,  there is explicit support for classes which dramatically simplifies the process of creating reusable objects.  I thought I would introduce them by means of a real- example: a notification window that shows progress when stepping through a sequence of time-consuming steps.

Creating an Object

I have a class ActivityStatusClass that displays an activity status window as illustrated above.  Before any class is used it first has to be defined.  But the benefit comes from its use, so let me focus on that first.  Here is an example of creating an instance of the ActivityStatusClass to show progress as I fit 4 nonlinear models (for the sake of clarity of code the nonlinear modelling is not relevant and has been replaced by wait statements!):

Line 2:  the class has been defined in a separate jsl file (of the same name).  The definition is referenced by including the file.

Line 11:  a new object is instantiated by calling the function newObject.  The name of the object is the name of the class (no quotes).  This particular object requires a single parameter which is the list of notifications created on line 4.

Line 13:  the method start launches the notification window and displays the first notification message.  Notice that the notation to invoke the method for the status object is the same notation that is used to refer to namespace variables (behind the scenes the status object is a namespace with a function definition for the status method).

Lines 16, 19, 22:  each time the method startNextTask is invoked, the previous activity is marked as complete (an hour glass icon is replaced with a green tick mark) and the notification message for the next activity is displayed.

Line 25:  the finish method marks the final activity as complete and after a momentary pause the status window is closed.

Line 26:  housekeeping: the object still resides in memory but can be removed by sending the delete message to it.  Note that is an object message and uses ‘<<” and not namespace colon notation.

So that’s how the object is used.  In general there are a few common steps:

  1. Reference the class definition (typically via an include statement)
  2. Create an object using the newObject function
  3. Invoke object-specific methods
  4. Delete the object when it is no longer required
Class Definition

Here is the definition of the class (as defined in the file “ActivityStatusClass.jsl”):

I’m not going to try and rationalise the code structure for the class definition, but here are a few observations:

  • Properties of the class can be identified by declaring variables with initialised values (see lines 8 through to 20); these act as public variables in that they are accessible to the code of all the class methods without any qualification.
  • Each property is delimited with a comma
  • Each method is standard JSL (i.e. expressions separated by semicolons).  Arguments can be optionally specified.
  • Unlike functions, the scope of variables inside a method definition does not need to be explicitly specified (there is no default local).  Variables are local to the method, except for those that have been defined outside of the method call that act as class-level properties.
  • There is a special initialisation method that has the name _init_.
  • Each method is delimited by  a comma (but don’t put a comma after the last method!)

With regard to this specific class definition the lines 15 and 16 define image icons based on a very long character string that would overwhelm the widget that I use to display code snippets – therefore I have replaced the text with “…”.  This will mean that the code will not run as intended – however, once JMP is officially being distributed I will post the code on the file exchange.


Leave a Reply

Your email address will not be published. Required fields are marked *