O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required