1. A well-designed module hides all of its implementation details, cleanly separating its API from its implementation. Modules then communicate only through their APIs and are oblivious to each others’ inner workings. This concept, known as information hiding or encapsulation, is one of the fundamental tenets of software design.
2. Information hiding decouples the modules that comprise a system, allowing them to be developed, tested, optimized, used, understood, and modified in isolation.
3. Make each class or member as inaccessible as possible.
4. For top-level (non-nested) classes and interfaces, there are only two possible access levels: package-private and public.
5. If a package-private top-level class (or interface) is used by only one class, consider making the top-level class a private nested class of the sole class that uses it.
6. For members (fields, methods, nested classes, and nested interfaces), there are four possible access levels, in order of increasing accessibility : private, package-private, protected, public.
7. If a method overrides a superclass method, it is not permitted to have a lower access level in the subclass than it does in the superclass.
8. It is acceptable to make a private member of a public class package-private in order to test it, but it is not acceptable to raise the accessibility any higher than that.
9. Instance fields should never be public.
10. Classes with public mutable fields are not thread-safe.
11. You can expose constants via public static final fields, assuming the constants form an integral part of the abstraction provided by the class. By convention, such fields have names consisting of capital letters, with words separated by underscores. It is critical that these fields contain either primitive values or references to immutable objects.
12. It is wrong for a class to have a public static final array field, or an accessor that returns such a field.
13. You can make the array filed private and add a public immutable list:
private static final Thing[] PRIVATE_VALUES = { ... }; public static final List<Thing> VALUES = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
Alternatively, you can make the array field private and add a public method that returns a copy of a private array:
private static final Thing[] PRIVATE_VALUES = { ... }; public static final Thing[] values() {return PRIVATE_VALUES.clone();}
相关推荐
Item 15: Minimize the accessibility of classes and members Item 16: In public classes, use accessor methods, not public fields Item 17: Minimize mutability Item 18: Favor composition over inheritance ...
Item 13: Use Proper Initialization for Static Class Members 77 Item 14: Minimize Duplicate Initialization Logic 79 Item 15: Utilize using and try/finally for Resource Cleanup 87 Item 16: Avoid ...
of the different processes, and then choose the appropriate method to minimize the effects of voltage dips, within the constraints of the supply and budget. The worst case scenario is that of a three ...
bumpless transfer (AWBT) compensation to minimize the adverse eflects of any control input nonlinearities on closed loop performance". The resulting AWBT compensation is applicable to multivariable ...
Description: Make the right architectural decisions up front and improve the quality and reliability of your results. Led by two enterprise programming experts, you ll learn how to apply the patterns ...
This book addresses the topic of software design: how to decompose complex software systems into modules (such as classes and methods) that can be implemented relatively independently. The book first ...
视频跟踪论文 We consider the problem of visual tracking of regions of interest in a sequence of motion ...to minimize the proposed cost function and demonstrate it on sequences of real blurred images.
The main purpose of this book is to help advance the real-world adoption and deployment anomaly detection technologies, by systematizing the body of existing knowledge on anomaly detection. This book ...
Develop the mathematical foundation needed to help minimize the impact of the problem using easy-to-understand language and examples Use diverse tools and techniques such as machine learning ...
Inductance Principle #3: When the Number of Field Line Loops Around a Conductor Changes, There Will Be a Voltage Induced Across the Ends of the Conductor Section 6.6. Partial Inductance Section 6.7. ...
See how optional parameters can minimize the number of method overloads (see Item 10) You’re already a successful C# programmer–this book will help you become an outstanding one. About the Author ...
Of course, .cc files typically do require the definitions of the classes they use, and usually have to include several header files. Note: If you use a symbol Foo in your source file, you should ...
the elements of a Web caching system and its desirable properties. Then, we survey the state-of-art techniques which have been used in Web caching systems. Finally, we discuss the research frontier in...
To address these current inadequacies, this book will introduce an automated method to minimize the data editing steps, generate a test script to test the entire application, and free you from having...
Written by leading members of the Ubuntu community, The Official Ubuntu Server Book, Third Edition, covers all you need to know to make the most of Ubuntu Server, whether you’re a beginner or a ...
As computing devices grow more ubiquitous, a larger part of our lives and work is recorded digitally, and as "Big Data" has gotten bigger, the theory of machine learning -- the foundation of efforts ...
This paper describes the general architecture of the interface, its current shortcomings and advantages, and presents a set of modeling results for short range acoustic propagation, which accounts ...
At present, the main ... they also cause extra errors on account of the effects of the ionosphere temporal and spatial gradients. Based on the analysis of these errors as well as the smoothing noise