Brian

4%
Flag icon
In the meantime, you can reduce this problem by drawing attention to static factories in class or interface documentation and by adhering to common naming conventions. Here are some common names for static factory methods. This list is far from exhaustive: • from—A type-conversion method that takes a single parameter and returns a corresponding instance of this type, for example: Date d = Date.from(instant); • of—An aggregation method that takes multiple parameters and returns an instance of this type that incorporates them, for example: Click here to view code image Set<Rank> faceCards = ...more
This highlight has been truncated due to consecutive passage length restrictions.
Brian
Good naming recommendations for common factory method patterns: • from(<obj to convert>) / valueOf • of(<list of objects to compose into obj>) • instance(<opts>) • create(<opts>) [alt. to instance that guarantees distinct instance from previous invocation, whereas instance may share singletons/oligarchs(?)] • get*Type*()/*type*(). [similar to instance, but for when factory method is in diff class from obj/interface returned] • new*Type*() [similar to create but for when factory method is in diff class from obj/interface returned]
Effective Java
Rate this book
Clear rating
Open Preview