Page 1 of 1

RFC for suggestion: setting access rights to added mixins

PostPosted: Tue Nov 06, 2012 12:55 am
by kobi7
Hi,
I have a class, that adds a mixin.
I would like to hide a few of the mixin public members/methods so as to only use them internally, but have them be invisible (private) to the outside consumer. (the hiding happens in the class, doesn't change the mixin itself)

Is this possible for mixins?

a way to accomplish this is to instantiate objects inside the class, and then create methods that mimic them -- manually exposing whichever I want,
but that's more work than I would like.

I think a support for setting access rights for specific methods in the added mixin would be an ideal solution.

please your comments

Re: RFC for suggestion: setting access rights to added mixin

PostPosted: Tue Nov 06, 2012 11:47 am
by Charles
"is protected"

This almost works:
mixin A

def one as int
return 1

def two as int is protected
return 2


class B adds A

def foo
trace .one
trace .two


class P

def main
b = B()
b.foo
b.one
# b.two

I had to comment out the last line because "two" is a protected member and cannot be seen by class P. Cobra correctly reports that error.

However, there is a bug in the code generation which prevents the above program from running. I should be able to fix later today.

Re: RFC for suggestion: setting access rights to added mixin

PostPosted: Wed Nov 07, 2012 11:17 am
by Charles
This is fixed now. Members can be protected and private. They are injected as is, into the class (or struct), so they become protected and private members of what they are added to.

There is currently no way to make a member private to the mixin. We can leave that as is or try to address it.

As you use mixins, keep sharing whatever issues you run into.

Re: RFC for suggestion: setting access rights to added mixin

PostPosted: Sun Nov 11, 2012 4:21 am
by kobi7
cool thanks!
I'll open another thread if I find more.