Changing Access Levels
The next technique for adjusting visibility is the simplest in concept, but often the most controversial in practice. The simplicity comes from simply changing a keyword in your method declarations. In Java or C++, you might change private to protected or protected to public.1 Java also offers package default as an escalation from private. In Perl’s Class::Std,2 you might change the PRIVATE trait to RESTRICTED or remove the RESTRICTED trait. You get the idea.
1. A programmer—one of the most talented I have known at just getting things to work—put #define private public in C++ before the headers of a third-party library to access members that were not otherwise exposed. Although I do not recommend using this technique, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access