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

Ian Haywood ihaywood at ...1979...
Sat Apr 20 07:08:10 CEST 2013


On Sat, Apr 20, 2013 at 11:13 AM, Bruce <bbruen at ...2308...> wrote:
> I have a deep hierarchy of classes, seven levels of specialisation so
> far and likely to grow.
wow.

> At level 4, 6 dummy and the 2 real parameters, i.e.
>         hObj = New
>         Level4Class(Null,Null,Null,Null,Null,Null,Source,Name)
>
> This is becoming very painful.
>
> Is there any way to "turn off" the way constructors consume parameters?
It's a core language design decision, so I doubt it.
Personally instead of using the "official" constructor _new I often
have a separate
Init( ) function which is called immediately after instantiation

foo = New MyClass()
foo.Init(someParameter)

Messy, but because .Init( ) is an "ordinary" function in the eyes of
the the Gambas compiler, ancestor
classes to not "consume" parameters in the same way, plus it is only
overridden in the hierarchy when required.

Unfortunately Gambas doesn't allow any change in function signatures,
so if you wanted an extra parameter in a descendant
constructor you would have to have an "Init2" method which then calls
"Me.Init()"

Ian




More information about the User mailing list