[Gambas-user] Gambas bug?

Fabián Flores Vadell fabianfloresvadell at ...626...
Sat Feb 11 17:09:20 CET 2012


2012/2/11 Bruce Bruen <bbruen at ...2308...>


> 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.
>

I catch it now.(I think). You want something like Friendly in C++. Right?

I dont like Friendly, in order to avoid the temptation of break the
encapsulation. But that would be a good feature to add for the reflexive
skills of Gambas.

-- 
Fabián Flores Vadell
www.comoprogramarcongambas.blogspot.com
www.speedbooksargentina.blogspot.com



More information about the User mailing list