JS Design Pattern - Object Creation Patterns (Chapter 5)

Object Creation Patterns Creating objects in JavaScript is easy: (1) object literal OR (2) constructor functions [No syntax] The JavaScript language is simple and straightforward; No syntax for such as namespaces, modules, packages, private properties, and static members. This topic...

Effective Java - Item 5 Unnecessary Objects

Item 5: Avoid creating unnecessary objects Item 5 says, “Don’t create a new object when you should reuse an existing one.”, while Item 39 says, “Don’t reuse an existing object when you should create a new one.” Failing to make...

Effective Java - Item 4 noninstantiability

Item 4: Enforce noninstantiability with a private constructor Occasionally you’ll want to write a class that is just a grouping of static methods and static fields. Such classes have acquired a bad reputation because some people abuse them to avoid...

Effective Java - Item 3 Singleton Property

Item 3: Enforce the singleton property with a private constructor or an enum type A singleton is simply a class that is instantiated exactly once Before 1.5: There were two ways to implement singletons. 1.the member is a final field:...

Effective Java - Item 2 Consider a builder

Item 2: Consider a builder when faced with many constructor parameters Static factories and constructors share a limitation: they do not scale well to large numbers of optional parameters. Problem: the telescoping constructor pattern works, but it is hard to...