Forums

RFC for suggestion: setting access rights to added mixins

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

RFC for suggestion: setting access rights to added mixins

Postby kobi7 » Tue Nov 06, 2012 12:55 am

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
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

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

Postby Charles » Tue Nov 06, 2012 11:47 am

"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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

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

Postby Charles » Wed Nov 07, 2012 11:17 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

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

Postby kobi7 » Sun Nov 11, 2012 4:21 am

cool thanks!
I'll open another thread if I find more.
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel


Return to Discussion

Who is online

Users browsing this forum: No registered users and 115 guests

cron