[Gambas-devel] Arguments of inherited constructors

Benoît Minisini gambas at ...1...
Mon Nov 30 12:41:00 CET 2009


Hi,

There is a change in the Gambas object model in the last revision, about 
arguments passed to inherited constructors.

Let's suppose that you have the following inheritance tree:

	A --> B --> C

When instanciating C, the constructor of A (its _new method) is automatically 
called, then the constructor of B, and finally the constructor of C.

If constructors have arguments, they must be passed to the NEW instruction.

Before the last change, the arguments had to be sent in reverse order:

	New C(Arguments for C._new, Arguments for B._new, Arguments for A._new)

Now, they have to be sent in normal order:

	New C(Arguments for A._new, Arguments for B._new, Arguments for C._new)

They are three consequences:

1) You can now have optional arguments in the C constructor.

2) Optional arguments in inherited constructors become mandatory. Note that 
only the initial constructor could have optional argument before, which I 
found finally illogical.

3) You must check your code! For example, if you created a form whose 
constructor has a string arguments, you had to do that before:

	MyForm = New MyForm(StringArgument)

And now you must do:

	MyForm = New MyForm(Null, StringArgument)

'Null' is actually the argument of the Window constructor, which is the parent 
of the Window.

Moreover, with that change, I may be able to fix the constructor signature 
that didn't take inheritance into account until now.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list