S
Simon L. Prinsloo
Guest
We are all grown up and responsible for what we do. Each person in society has the responsibility to know the rules and abide, or carry the consequences. We know we must not speed on the high ways. Most of the time you would most likely get away with it. But when you are caught, you have to take the rap. Protection, including package level protection, is not a policeman, but a road sign imposing (or lifting) some limit. It is a tool assisting you to know the local rules. If your mind wander off and you start speeding, the GPS will see that and inform you that you are transgressing. You can adjust or you can simply switch it off. What you can't do, once you switched it off, is to claim that you did not know. The same goes for the compiler. It will protect me if I attempt to transgress, but if I intentionally take action to evade it, I can't blame anybody else when it comes back to haunt me. When a programmer bestow a certain protection on something, the programmer signal a certain intent. This means that the rest of us have been informed and if someone do not head the warning, that person have to bear the consequences. Another helpful benefit of protection comes in tooling, where you only see what is relevant. When I consume a class from a different package, it would be quite helpful and time saving if I only saw what is relevant, rather than to wonder if the developer intended that I use either CreateEntry() or NewEntry(), not knowing that one is part of the package's interface and the other is actually for internal use. It gets worse if CreateEntry() is the package method, because once I find it, I will most likely stop reading and run into all sorts of trouble, not even realising that there is a better alternative. If it was clearly marked as package level, most of us will read on. When we get to reflection, we are in essence bypassing the normal rules in order to achieve some non-functional goal, e.g. generating code or doing a unit test, rather than creating a financial transaction or issuing some certificate. In my mind it is advanced territory where most people do not need to go. But having rules in that domain to guide you when you enter it (e.g. using an option to intentionally make the private accessible) makes life much simpler for everybody than having cart blanch until you are stopped.
Continue reading...
Continue reading...