[Gambas-user] How to stop "Greedy" constructors consuming parameters

Bruce bbruen at ...2308...
Sat Apr 20 13:18:41 CEST 2013


On Sat, 2013-04-20 at 11:36 +0200, Fabien Bodard wrote:
> The check is not done for the "_new" special method, as the inheritance of
> _new is special (see "inheritance and constructor" in the "Gambas object
> model" documentation on the wiki).

Yep, I know that, but Ian's comment was about overrides for "normal"
methods. Which still for the sake of sanity I could never understand the
need for a total ban on signature changes.  

I can appreciate that the return type should to some extent be
"prevented" from overrides, although even that is questionable in cases
like abstract factories.  As I said at the time, I could not see, nor
have experienced a situation where gambas has failed where a method is
overridden in a child class that has a requirement for a different
signature.

In particular, where an ancestral non-instantiable root class has no
implementation of some method "XXXX" and the root class is abstract, it
is fairly easy to specify a method in that class that must be
overridden. In other words a stub that looks something like this

  Public Sub XXXX(...)
    Error.Raise(Subst("Incomplete override &1", Object.Class(Me).Name))
  End

So now I have declared a method in the root class, which MUST be
overridden in the instantiable child classes, by some method which may
require {0,1,2,... many} parameters.  As of the fix for Issue 78 this
doesn't work "nicely", because every override method in a child class
MUST use the signature "Public Sub XXXX(...)"

The solution I "suggested" to Ian is based on optionally compiling out
the signature check in gbx-class.c which as I said has not failed for
about 2 years. I would really love to see an example of where this
approach could fail because I am still running and promulgating a
modified version of Gambas locally and to all the clients that has this
patch in it.

If this sounds like a bit of a rave then I apologise, but "for the sake
of sanity"...

Anyway, so much for the coffee break, back to rewriting the 64 classes
to use Ian's "_new()/Init()" approach. Grrrr!

cheers
Bruce      





More information about the User mailing list