Is it only me who wants to see the friend access visibility added to PHP so classes within the same package can call each others methods? Now we have Namespaces in 5.3 I see no reason why this form of access visibility has been left out.
Friend or Internal as it is called in C# is added to methods or properties so that only classess in the same packages can access them. I remember in C++ you could actually allow access from classes outside the package, but whenever I needed to do that I then found I could improve the design of my application to keep coupling down.
I often find that when developing an API I have to make many more of the methods public so other classes in the same package can interact, however I don't intend for the end user of the API to every call these methods. This weakens the API because the internal state of object can be changed by the user often simply by mistake but it can cause unnecessary pain for the user or a lot of additional validation within the class making the code bigger and perform worse.
I'm going to follow this up with some examples, but if anyone has any good examples where software design can be improved by the use of Friends please let me know.
Like what you've read?