Abstract Class Clarion

Is there any way to define an abstract class with abstract methods in Clarion?

Best Regards

Is there something about INTERFACE that would not do the job for you?

1 Like

There sort of was through 13505, but it has been removed in the most recent release 13630. They plan on a different way … in a future release.

IIRC you put VIRTUAL,TYPE on each abstract Procedure. Then you would put DERIVED on the inherited class methods. So not an abstract class, but abstract methods that must be implemented.

Maybe they’ll do a true abstract class like C++ head

What I would love to see (a la C++) is parameters for constructors. Then you could do stuff like:

MyClassRef &= NEW MyClass(‘MyParameter’,‘MyOtherParameter’)

Agreed, granted you can get a little tricky…

MyClassRef &ctMyClass
    MyClassRef &= MyClassRef.New('MyParameter','MyOtherParameter')

ctMyClass.New PROCEURE(STRING xParam1, STRING xParam2) !,*ctMyClass
Answer   &ctMyClass
   Answer &= NEW ctMyClass
   Answer.Prop1 = xParam1
   Answer.Prop2 = xParam2
   RETURN Answer

NOTE: I’m using what I refer to as a static notation
where MyClassRef is in fact NULL when I call the NEW method

WARNING: several people I’ve spoken to, really do NOT LIKE this static notation

but it is safe as long as you never touch a property in the method being called
you can call other methods, as long as they to do not touch properties.

This comes down to the mechanism that clarion uses for classes
when you call MyClass.MyMethod(arg1, arg2)
clarion really calls myMethod(MyClass, arg1, arg2)
so, in the case of the ‘static notaton’ you’re just passing a NULL parameter
and it turns out that’s safe as long as you never try to deference the NULL parameter
by writing SELF.SomeProp

Note: I haven’t tested this exact code, there is a chance that you’ll need to rename the method NEW to something else as NEW is a clarion keyword. For example _New or MyNew


That could also be just a non-method procedure without static notation. A la NewCriticalSection().

1 Like

Thank you all for the answers, I will have to come up with another way to achieve what I want, maybe one more idea will not hurt. What I need is to have a common procedure to several classes, in fact it is a data validator, any suggestions?

Thanks a lot

Not a lot to go one from what you said, but what about either a base class or an interface?

It’s a good idea, what I have defined is a validator class and that the rest of the classes inherit from it, so far it works I do not know what complications it will bring me in the future but thanks for the help

It occurred to me I had previous posted an example on this topic