Design Patterns: Factory Pattern

What is a Factory Pattern?
Factory Pattern take cares of the creation of objects and hides the implementation from the client. Think of a real factory that make cars and there are different type of cars eg. sedans, hatch backs, and suvs.

When do You Use it?
You should use this pattern when you have a code that creates new object of different type but each object has the same method. The code below is a client method called Buy() that has a switch statement that determine which type of car object to instantiate to get the price. (more…)