More on this book
Community
Kindle Notes & Highlights
Grammar and vocabulary are properties of the language alone, but usage is characteristic of a community that uses it.
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.
Small is beautiful, but simple ain’t easy.
It was inevitable that the book would grow, and grow it did, from fifty-seven items to seventy-eight.
I naturally think in terms of exported APIs (Application Programming Interfaces), and I encourage you to do likewise.
The fundamental goals of refactoring are the improvement of system structure and the avoidance of code duplication.
The user of a component should never be surprised by its behavior.
Components should be as small as possible but no smaller.
Code should be reused rather than copied.
The dependencies between components should be kept to a minimum.
Learning the art of programming, like most other disciplines, consists of first learning the rules and then learning when to break them.
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.
The traditional way for a class to allow a client to obtain an instance is to provide a public constructor.
A class can provide a public static factory method, which is simply a static method that returns an instance of the class.
One advantage of static factory methods is that, unlike constructors, they have names.
A class can have only a single constructor with a given signature.
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.
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.
A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type.
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.
Static factories and constructors share a limitation: they do not scale well to large numbers of optional parameters.
Attempting to enforce noninstantiability by making a class abstract does not work. The class can be subclassed and the subclass instantiated.
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: