Friday, November 22, 2013

Creation Patterns

Creation patterns are a group of patterns that solve one problem: build a concrete object of what you want when you want it how you need it.

What are some of the creation patterns?
  • Factories - These patterns take in a set of parameters and returns a concrete class typically as a base type or an interface.  When is this pattern helpful?  Do you integrate with several API's that do the same thing with different methods?  Do you have several types that all inherit from a single base type?  In every case, you want to build a specific concrete class, but you only care about the base class or interface functionality.
  • Builders - These patterns build a concrete class.  One point behind this pattern is to get all that boilerplate initialization in one nice little place so that it's not sprinkled all over your application and so that it may not have to change at every sprinkle should the need to change arise.  How could it change?  A new parameter of course.  May want to check in on that Open/Closed principle before you go down that path.  The other point of this pattern is to prevent a long list of constructors in the class definitions.
  • Object Pools - This pattern provides a cache of resources already acquired for the purpose of fast initialization.  You see these often with network based connections like database connections.

1 comment:

  1. You have given me a whole new outlook on patterns and what you can expect them to accomplish. Very interesting.

    ReplyDelete