Quantcast

Friend functionality

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Friend functionality

Leon Davis
Gambas v3.9.2 using GTK+3

In Microsoft VB there is a "Friend" designation that allows classes in the
same project to access each others members while protecting  those members
access from the dot notation. Example: a programmer cannot access a friend
member by typing "MyClass.ClassMember". Is that functionality available in
Gambas?
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Friend functionality

Tobias Boege-2
On Sat, 29 Apr 2017, Leon Davis wrote:
> Gambas v3.9.2 using GTK+3
>
> In Microsoft VB there is a "Friend" designation that allows classes in the
> same project to access each others members while protecting  those members
> access from the dot notation. Example: a programmer cannot access a friend
> member by typing "MyClass.ClassMember". Is that functionality available in
> Gambas?

It's not. I think the usual replacement pattern for this in Gambas is to
declare a pair of functions:

  Public Sub _SetClassMember(Value As Type)
  Public Function _GetClassMember() As Type

The leading underscore makes the function names hidden in the IDE, but you
can still access them despite being hidden:

  MyClass._SetClassMember(x)
  Print MyClass._GetClassMember()

Of course, this offers no real protection. Anyone can use these functions
from anywhere. You just have to keep the existence of these functions a
secret between MyClass and its "friends". For example, did you know that
gb.gui.base's GridView class lets you raise its Select event at will if
you call GridView._RaiseSelect()?

Gambas has Public and Private for visibility, Read and the absence of Read
for access and Static for storage. I hope I remember correctly that Benoit
stated that he doesn't want the Gambas OO mechanisms to become as convoluted
as C++'s. This probably includes the modifiers friend, protected, virtual,
final and what have you from other languages, as well as multiple inheritance,
polymorphism (sadly) and operator overloading (which is actually available
to some extent for native components).

Regards,
Tobi

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

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Friend functionality

Leon Davis
Thank you very much for your help

Regards
Leon

On Sat, Apr 29, 2017 at 8:05 AM, Tobias Boege <[hidden email]> wrote:

> On Sat, 29 Apr 2017, Leon Davis wrote:
> > Gambas v3.9.2 using GTK+3
> >
> > In Microsoft VB there is a "Friend" designation that allows classes in
> the
> > same project to access each others members while protecting  those
> members
> > access from the dot notation. Example: a programmer cannot access a
> friend
> > member by typing "MyClass.ClassMember". Is that functionality available
> in
> > Gambas?
>
> It's not. I think the usual replacement pattern for this in Gambas is to
> declare a pair of functions:
>
>   Public Sub _SetClassMember(Value As Type)
>   Public Function _GetClassMember() As Type
>
> The leading underscore makes the function names hidden in the IDE, but you
> can still access them despite being hidden:
>
>   MyClass._SetClassMember(x)
>   Print MyClass._GetClassMember()
>
> Of course, this offers no real protection. Anyone can use these functions
> from anywhere. You just have to keep the existence of these functions a
> secret between MyClass and its "friends". For example, did you know that
> gb.gui.base's GridView class lets you raise its Select event at will if
> you call GridView._RaiseSelect()?
>
> Gambas has Public and Private for visibility, Read and the absence of Read
> for access and Static for storage. I hope I remember correctly that Benoit
> stated that he doesn't want the Gambas OO mechanisms to become as
> convoluted
> as C++'s. This probably includes the modifiers friend, protected, virtual,
> final and what have you from other languages, as well as multiple
> inheritance,
> polymorphism (sadly) and operator overloading (which is actually available
> to some extent for native components).
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...