Now, the point of a Factory pattern, is the creation of various objects types. So, as you can see I selected the pizza. I create three pizza types, all of them extend a base pizza class. Cheese, Pepperoni and Deluxe. Now, each type prints out a lable telling us what it is once it is created. FYI I did this in jsfiddle and you are more than welcome to play around and experiment…this is why I used jsfiddle. :)
The factory method uses a simple switch to figure out which object we want and then create it. I use an array to load the three types and some main body code to run through the array and fire off the factory method for each type. It's a rather smooth little test if I say so myself!
Now, please feel free to pick me apart and offer up suggestions or comments! This is done entire as a learning process for me, so I do not give any assurances that this is the best way to implement such a pattern. Please let me know if you have a better way!