Java Effective - III
90 points to make your coffee

3. Classes and Interfaces

Classes and interfaces lie at the heart of the Java programming language. They are its basic units of abstraction. The language provides many powerful elements that you can use to design classes and interfaces. This chapter contains guidelines to help you make the best use of these elements so that your classes and interfaces are usable, robust, and flexible.

15. Minimize access to class members

- A well designed component hides all implementation details from it's API, ie abstraction. This allows components to be used,developed,tested in isolation without impacting the API.
- A solid rule of thumb for access modifiers is to make each class or member as inaccessible as possible, lowest  level of access that allows for its functionality.
- Classes/Interfaces are public or default(package-private). Keep classes package-private whenever possible, or if a class is used only from one another class, keep it as a static inner class. Public classes are a part of the API while package-private classes are a part of the implementation.
- For members (fields,methods,nested classes,nested interfaces) it is private, package-private, protected or public.
- After designing the class API, all others members should be private by default. Private and package-private are a part of implementation and not in design. Public and protected are a part of the API and needs to be supported.
- Instance fields should almost never be public. Constants are the exception, but even constants shouldn't be a mutable type.
- Java9 module system brings in an additional layer of access control with public/protected classes being avilable only within module unless exposed from within module-info.java. But this can be bypassed by adding jars directly to a class-path instead of the module-path. Module access protection is purely advisory.

16. In public classes use accessors into fields

17. Minimize mutability

18. Composition over inheritance

19. Design and document for inheritance or prohibit it

20. Prefer interfaces to abstract classes

21. Design interfaces for posterity

22. Use interfaces only to define types

23. Prefer class hierarchies to tagged classes

24. Prefer static member classes to non-Static

25. Limit source files to a single top-level class

*****
Written by Martin on 20 May 2019