OO ABL language enhancements / questions

Posted by Admin on 13-Aug-2008 05:11

Hello everybody. I'm new to OO ABL. I do have some OO experience (.Net C# and C++) and I expected that it would be easy to apply this knowledge in OO ABL. Unfortunately some things are a little different while others are missing. I there a place where I can learn what those difference exactly are?

Does any body now how to implement events in OO ABL? I have read that publish/subscribe cannot be used. In .Net I can do this:

class uiController

{

event EventHandler CurrentPageChanged;

...

protected virtual void OnCurrentPageChanged(EventArgs e)

{

if (CurrentPageChanged != null)

CurrentPageChanged(this, e);

}

}

This allows other classes to attach themselves to this event and respond to it whenever it occurs in the following way:

uiController.CurrentPageChanged += new EventHandler(onCurrentPageChanged);

Now, when from within the uiController class the virtual OnShapeChanged method is executed, all (if any) connected methods get executed.

This is a very useful mechanism to have several objects respond to state changes in each other. But reading the help files I think this is not (yet) possible?

Or is it? How do implement this kind of behaviour without going "back" to regular ABL?

ps. On another thread someone requested support for generics. That would certainly be appreciated.

All Replies

Posted by Admin on 13-Aug-2008 05:59

There's not (yet) such a feature like event support between classes.

Classes and procedures can subscribe to .NET events. If a class inherits from a .NET class, this is like the ABL class publishing this event.

Classes can PUBLISH to procedures (using the PUBLISH FROM SESSION:FIRST-PROCEDURE syntax).

A workaround for the missing event support can be implemented using Interfaces. The subscriber needs to implement an interface of all the event (methods). The publisher needs to offer a method "AddListener" or "AddSubriber" with an input parameter of the Interface type. The publisher needs to manage multiple subscriber (in a temp-table for instance). To publish an event, simply FOR EACH the temp-table, CAST the reference to the Interface and execute the event (method) in the subscriber.

For a general OO reference, there is a getting started document in the getting started section of the PDF docs. I doubt there is a document listing differences to C# or C++ or even Java.

Posted by Admin on 19-Aug-2008 06:45

Thanks for your answer. At least I know now it isn't there and that I will have to come up with a solution myself. Would you recommend creating something like a Isubscribeable interface? Or maybe it will be easier to write a 4gl library to handle both the publish and the subscribe of classes. That would not be type safe or available thrue intellisense but it will be "easy".

Ps. Did you just say that a method/interface can be passed as a parameter/object?

Posted by Admin on 19-Aug-2008 08:01

You need to create an Interface for every type of subscriber. Let's say you have a toolbar object and that toolbar knows how to do some things with a viewer and others with a data source. Then you need two Interfaces:

- ITableIOSubscriber

- IDataSourceEventSubscriber

In this case the toolbar needs a method VOID AddTableIOSubscriber (po-subscriber AS ITableIOSubscriber) and another method VOID AddDataSourceEventSubscriber (po-subscriber AS IDataSourceEventSubscriber). Of course thees two methods could be inforced by an interface as well to provide a better abstraction when using multiple different types of toolbars.

You can't pass a method name as a parameter. That would require dynamic invokation (like a run value) on classes. That's not part of the language (yet?).

You can pass an object instance reference as a parameter of an Interface type. That way you can call all methods defined in the interface on that parameter.

This thread is closed