Now, in C++ or Java, you can use the combination of access restrictions on classes and/or internal classes such that My::B would have been sufficiently hidden from any external code save for My::A. Typically, the My::B class would be in the same file as My::A declarations and definitions.
In perl, it's nay impossible to hide such a class (TTBOMK). So there's two possible options I can see: either put the definition of My::B in My::A's file as:
or to put B into it's own file:# ./My/A.pm package My::B; # ... # ... package My::A; # ... # ...
In neither case, My::B isn't protected as the user would still be able to gain access to My::B, so worrying about this issue is a forgone conclusion. Thus, it's now mostly a semantics question -- which is the better or preferred way of doing this? The only advantage that it would see to me is using separate files, it's more obvious during use statements that the user is bringing My::B into the block, as opposed to the single file approach; of course, this again makes My::B more accessible that it might seem.# ./My/A.pm package My::A; use My::B; # ... # ... # ./My/B.pm package My::B; # ... # ...
(Now of course, I put the cavaet that such hiding may be determined by the initial design, but down the road, it may be determined that allowing the user to inherit from My::B may be useful or important, so the fact that such code is not hidden by perl to start may be a good thing.
Update I should state that I fully understand that I cannot 'protect' my class from being instaniated as demerphq points out (and I like his analogy as well). Given that, I'm more looking for how I place the class def into files as to indicate to the user as best as possible that they really shouldn't instaniate the class, and/or to make it fit the perl philosophy more.
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
In reply to Private Classes - Same or Separate Files? by Masem
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |