Effective Java
Rate it:
Open Preview
Started reading November 26, 2024
1%
Flag icon
Grammar and vocabulary are properties of the language alone, but usage is characteristic of a community that uses it.
1%
Flag icon
It’s typically not enough to produce code that operates effectively and is readily understood by other persons; one must also organize the code so that it is easy to modify.
2%
Flag icon
Small is beautiful, but simple ain’t easy.
2%
Flag icon
It was inevitable that the book would grow, and grow it did, from fifty-seven items to seventy-eight.
2%
Flag icon
I naturally think in terms of exported APIs (Application Programming Interfaces), and I encourage you to do likewise.
2%
Flag icon
The fundamental goals of refactoring are the improvement of system structure and the avoidance of code duplication.
3%
Flag icon
The user of a component should never be surprised by its behavior.
3%
Flag icon
Components should be as small as possible but no smaller.
3%
Flag icon
Code should be reused rather than copied.
3%
Flag icon
The dependencies between components should be kept to a minimum.
3%
Flag icon
Learning the art of programming, like most other disciplines, consists of first learning the rules and then learning when to break them.
3%
Flag icon
The term exported API, or simply API, refers to the classes, interfaces, constructors, members, and serialized forms by which a programmer accesses a class, interface, or package.
3%
Flag icon
The traditional way for a class to allow a client to obtain an instance is to provide a public constructor.
3%
Flag icon
A class can provide a public static factory method, which is simply a static method that returns an instance of the class.
3%
Flag icon
One advantage of static factory methods is that, unlike constructors, they have names.
3%
Flag icon
A class can have only a single constructor with a given signature.
3%
Flag icon
A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked.
4%
Flag icon
The ability of static factory methods to return the same object from repeated invocations allows classes to maintain strict control over what instances exist at any time.
4%
Flag icon
A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type.
4%
Flag icon
A fourth advantage of static factories is that the class of the returned object can vary from call to call as a function of the input parameters.
4%
Flag icon
Static factories and constructors share a limitation: they do not scale well to large numbers of optional parameters.
6%
Flag icon
Attempting to enforce noninstantiability by making a class abstract does not work. The class can be subclassed and the subclass instantiated.
6%
Flag icon
A default constructor is generated only if a class contains no explicit constructors, so a class can be made noninstantiable by including a private constructor: