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, ...
Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.