« Risposta #1 il: 29 Aprile 2013, 17:38:07 »
...continua...
«
The signature check is actually a bug fix.
Let's suppose that class B inherits class A, and that A has a method
foo() which is reimplemented in B with a different signature.
Then, calling X.foo() may lead to a crash if X is declared as an A and
is actually a B, because of an internal optimization that replaces an
expensive table symbol lookup by a direct method access.
If *all* of the classes of your hierarchy wants a 'Source' and 'Name'
argument, then these arguments must be defined in the root class
constructor, not in each one!
If theses twwo arguments must be handled differently between classes,
then add a public method to handle them. Prefix its name with an
underscore, to indicate that it must not be called outside of the
implementation.
' Root classPublic Sub _new(Source as String[], Name as String)
_Init(Source, Name)
End
' Any child classPublic Sub _Init(Source as String[], Name as String)
...
End
Does it fit your needs?
--
Benoît Minisini »
«
This is rule around underscores enforced by the compiler (a la Python)
or only a convention?
would you consider a Protected access type (like C++) instead?
Ian »
«
No, I always explained that in a previous mail (don't remember which one).
I prefer using a convention, to prevent confusion on what really happens
in the background (and keep simplicity).
"protected" in C++ is a convention enforced by the compiler, but it's
still a public method, i.e. a method that can be called outside of a
class (even if it is a child class).
I often saw C++ programmers that do not understand how all that klingon
object-oriented syntax is implemented in the background. In Gambas, the
syntax is far more... basic, but what happens is more clear (you just
can be "public" or "private").
Regards,
--
Benoît Minisini »
« Ultima modifica: 30 Aprile 2013, 11:40:41 da vuott »
Registrato
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »