Testability
Code testability is another area where encapsulation helps. If the implementation details were not hidden, we would need to test every single line of code and change the test every time we change any line of the implementation. But hiding the details behind the facade of the API allows us to focus only on the test cases that are required and limited by the set of possible input data (parameter values).
Also, there are frameworks that allow us to create an object that returns a certain result based on the certain value of the input parameters. Mockito is a popular framework that does it (http://site.mockito.org). Such objects are called mock objects. They are especially helpful when you need to get certain results from methods ...
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