Tips and tricks

Creational patterns allow for specialized behavior in creating objects. In many cases, such as the factory, they provide extension points into which crosscutting logic can be placed. That is to say logic that applies to a number of different types of objects. If you're looking for a way to inject, say, logging throughout your application, then being able to hook into a factory is of great utility.

For all the utility of these creational patterns they should not be used very frequently. The vast majority of your object instantiations should still be just the normal method of improving the objects. Although it is tempting to treat everything as a nail when you've got a new hammer, the truth is that each situation needs to have a specific strategy. All these patterns are more complicated than simply using new and complicated code is more liable to have bugs than simple code. Use new whenever possible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset