On Wed, 16 Apr 2014, Bruno F??lix Rezende Ribeiro wrote:
> Em Tue, 15 Apr 2014 12:55:51 +0200
> Tobias Boege <[email protected]> escreveu:
> 
> > And finally let me tell you something about extending classes: it gets
> > especially cool when you call your extending class like the extended
> > class. Above, you would not call your class VariantArray but
> > Variant[]. [ At present, you have to create .src/Variant[].class
> > outside of the IDE in your project because the IDE forbids use of
> > brackets in class names. However, the interpreter doesn't seem to
> > have any problems with that. ]
> > 
> > That way, you are overriding the Variant[] class in the interpreter's
> > global symbol table, using inheritance, i.e. you extend it. You can
> > add features to Variant[] which are immediately available to all
> > users of the Variant[] class without having to change any code.
> > That's explained in the docs as well[1].
> 
> Strangely this extension trick doesn't work with an array of a
> non-native class.  The interpreter doesn't complain, but no events or
> methods defined in the extended class are raised or called.  Could you
> please confirm this?  Do you think this is a bug?  If not, do you have
> an explanation for this strange behavior?
> 

Interesting point. We were only interested in Variant[] when we worked out
that solution (our goal was to make homogeneous (all elements have the same
type) Variant[] sortable as if it was a specialised native array of that
type), so that problem didn't emerge.

If my understanding is right (s. gbx_class.c), the behaviour makes sense as
follows: native array classes are included explicitely in the interpreter,
but non-native arrays are derived on-the-fly at runtime.

So, if you create a NativeDatatype[].class, you override that included
class, as you have seen, and everything is OK.

If you create MyClass[].class, this will actually be the original class, as
there is no MyClass[] in the interpreter's global symbol table yet. If you
later reference MyClass[] somewhere in actual code, the interpreter will
derive an array class from MyClass and override *your* class. That means
that your class' logic is irretrievably lost for the interpreter (as his
derived array classes will not call Super methods).

This would explain what happens, but Benoit knows better.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Gambas-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to