r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
407 stars 56 forks source link

acces priavte memebers from another reference class #59

Closed agstudy closed 9 years ago

agstudy commented 9 years ago

Within R6 class, is there any possibility to access a private member outside the class or at least from another R6 class?

wch commented 9 years ago

No, sorry. Private members can only be accessed within the class or a subclass.

piccolbo commented 9 years ago

Don't want to reopen this necessarily, but I was wondering if there is a recommended practice for these use cases:

I think it's a feature of R6 to seriously enforce information hiding. Not asking to weaken this guarantee. I just would like to compare notes with other people facing these problems. C++ for instance has the notion of friend functions and classes to selectively bypass information hiding. What should we do in R6?

wch commented 9 years ago

For the first, I don't know of a good solution offhand. For the second, I've been considering adding static (or class) methods: #66.

piccolbo commented 9 years ago

Got it, thanks. I think you are on the right track by making private members really, strongly private, not wishy washy private.