[Gambas-user] How to stop "Greedy" constructors consuming parameters
Benoît Minisini
gambas at ...1...
Tue Apr 30 10:41:38 CEST 2013
Le 30/04/2013 05:05, Ian Haywood a écrit :
> On 30/04/13 00:34, Benoît Minisini wrote:
>
>> 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 class
>> Public Sub _new(Source as String[], Name as String)
>> _Init(Source, Name)
>> End
>>
>> ' Any child class
>> Public Sub _Init(Source as String[], Name as String)
> This is rule around underscores enforced by the compiler (a la Python)
> or only a convention?
It's a convention used everywhere in the Gambas source code.
>
> 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
More information about the User
mailing list