4 ms·
Wait a minute. How would using a collaborator class as a "functor" for your formerly private methods improve encapsulation? At worst, if the collaborator were
by mquander 17y ago
Wait a minute. How would using a collaborator class as a "functor" for your formerly private methods improve encapsulation? At worst, if the collaborator were public, now other people with no use for your methods would be able to use them; at best, if it were a "friend" class or the equivalent, you would be exactly where you started, and only the caller would be using the method.
- joe_the_user 17y agoI think the approach the author is talking about is creating an internal class (either private or public). It's common approach for large libraries. Each STL container has a public iterator class contained in it and rails is filled with internal, private classes that implement the public functionality. That said, I don't think such constructs necessarily make code more understandable. Unless your project is really large scale, they're more like an exercise in showing the language and design constructs you've learned.