|Just another Perl shrine|
Re: Re^2: characterstics of private in perlby demerphq (Chancellor)
|on Mar 09, 2003 at 15:21 UTC||Need Help??|
I would say the short answer is yes, and the long answer is the same. Closures and inside-out objects are just as "private" as C++ private vars.
Well, my understanding of the above is that with sufficient trickery the data isnt really private. But I also agree that they are more or less equivelently private as compared to other things. I just dont agree that there is really a need for them in most cases.
The questions is very relevant. Good encapsulation is necessary to produce solid libaries without hidden dependencies.
The way I see it the question "How do I do private object attributes" is not the same as "How to I avoid object attribute namespace clashes in inheritance". I would say that the first is just one answer to the second, the one that in many ways is the simplest to implement and may have certain interesting properties, but not the only nor necessarily the best answer by any means.
Now, what are the options:
Well I can think of bunch of options besides closures/inside out objects. The most immediate strategy I would take would be to use a single, package specific key, then put all my attributes under that. If one day the original object was changed to have a key for its own use with the name of my package, well then I would be suprised.
To me the point is this, if an author wishes to create a class that is intended to be used as a baseclass he had better take care to organize the object in such a way that this isnt a problem. This could be something like this code
We have now have more or less addressed the real problem that you wanted solved, and without introducing privacy. We can call package_attrs with a package name to twiddle their attributes if we want to, and we probably won't do so accidentally.
I agree that in some ways its too bad that there isn't a clearly defined framework that we can all be comfortable within, and its good that Perl6 will address that. I just dont agree that there is no other way than introducing purely private variables.
I agree that designing an OO framework with heavy use of inheritance in mind requires a bit of effort. But usually you only have to do it for the base class and then its not that much effort to use.