Posted 11/09/10 01:05:00 pm
Pattern Name: Factory Method pattern
Type: Creational
The factory method pattern is an incredibly useful pattern that takes polymorphism to another level. Remember, polymorphism is the practice of creating inherited code that gets masked as it's parent object.
The Pattern
The primary purpose of the factory method pattern is to return a newly created object without specifically calling the constructor of class you want to create outside of the factory. Essentially, the factory has a method that typically harbors a switch...case statement based on some passed in parameter (usually some kind of type) and returns an object based on what was passed in. Let's look at a game example:
Comments
Post a Comment