Software Design/Minimize the accessibility of classes and members
Appearance
Checklist questions:
- Can the class be private to the package (enclosing class)?
- Can the function be private to the class (class and its subclasses, package)?
- Can the field (constant) be private to the class (package)?
This practice corresponds to rule Minimize exposure of members from C++ Core Guidelines.
Why
[edit | edit source]Minimizing the accessibility of classes, functions, and fields is the primary way of increasing encapsulation of a component, that helps to keep the components loosely coupled and the connascence low. This, in turn, makes understanding, change, testing, and debugging of individual components easier.[1]
References
[edit | edit source]- ↑ Effective Java (3 ed.). 2018. ISBN 978-0134685991. Item 15: "Minimize the accessibility of classes and members"