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** - **Importance:** Proper initialization ensures thread safety and avoids potential race conditions. - **Best Practice:** Initialize ...
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 ...
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. ...
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 ...
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 ...
The white paper "Lean Manufacturing: Production Flows and Activities AX2012" is focused on the implementation and understanding of lean manufacturing concepts within the Microsoft Dynamics AX2012 ...
Chapter 16 of the "Financial Management" course discusses the concept of financial leverage and capital structure policy, which are crucial elements in determining the financial health and overall ...
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 ...
- **Operator Requirements**: Calculating the number of operators needed based on the takt time and workload. - **Line Balancing**: Ensuring that each workstation has an equal amount of work to prevent...
Organizations should utilize this document as a reference guide for training and evaluating the skills of their development teams. Additionally, integrating secure development lifecycle practices ...
The **HX8347-D(T)** is a TFT (Thin Film Transistor) mobile single chip driver designed for driving displays with a resolution of 240RGBx320 dots and 262K colors. This device incorporates an internal ...
- **2.5.2 Duality Principle:** The principle that every algebraic expression derived by the laws of Boolean algebra remains valid if the operators and identity elements are interchanged. - **2.5.3 ...
- **Define Scope and Objectives**: Clearly define the scope and objectives of testing. - **Select Tools and Resources**: Choose appropriate tools and allocate necessary resources. - **Create a ...