[Gambas-user] Gambas bug?

Bruce Bruen bbruen at ...2308...
Sat Feb 11 08:36:03 CET 2012


On Fri, 2012-02-10 at 21:59 -0300, Fabián Flores Vadell wrote:
> 2012/2/10 Emil Lenngren <emil.lenngren at ...626...>
> 
<etc>

Interesting, I have a similar problem, perhaps the same but maybe
slightly different.

I have a base class that is CREATE PRIVATE, it cannot be instantiated
directly by a client application.  It contains various methods that must
be available to it's child classes (which CAN be instantiated) and can
be called by the client application.  For example, DBAdd is public in
the base class so that the child class can call it.  

What I have done, with some success is as follows:

In the base class I inspect the System.Backtrace and compare the object
indicated by the second item (i.e. System.Backtrace[1]) to see that it
"IS" a Me.  (is that clear, if not I'll have to go find the code?)
IOW I check that the caller object is an instance of Me, which can only
be the base class itself or a class that inherits the base class. If
not, I just raise an "Illegal Call" error.

This works within reason, however it has the following drawbacks:
a) there is obviously an overhead involved in the check code
b) it does not prevent a client application from instantiating an object
that inherits directly from the base class.
So it goes.

To expand this further.  I also have examples where I need (read "want")
to have methods in the base class that MUST be overridden in the
specialised child classes.  This is because these methods are templates
only. However, they must be present in the base class, as the base class
calls these methods!  IOW the base class calls "SomeMethod", which my
design says "must be implemented in the child class".  Gambas is
(almost) great at achieving this by its' use of virtual dispatch. If the
child class has correctly overridden the base class method, then that is
the one that is called.  And in the base class, I can have a "stub"
method that simply raises an error.  If the child class does not
override the method the the error is raised.

I would love to be able to solve problem b) above.

But hope this helps.
Bruce





More information about the User mailing list