The Simple Factory pattern
Kitty decides to do a little research on patterns. She wasn’t a computer science major in college and had only heard of patterns in her coding class. Kitty looks around and finds some blog articles on something called the Simple Factory pattern. Perfect, she thinks. This being her first coding project since college, and since she has a lot riding on her code (see what I did there?), she decides that something with simple right there in the name is a good place to start.
According to the blogs, all she has to do is move her instantiation logic into its own class, called a factory class. This is done, say the articles, to decouple the instantiation logic from the main program. This should get her closer to honoring the open-closed principle and should make her code more flexible.
She returns to her IDE and adds a class called SimpleBicycleFactory
and moves her instantiation logic there. The logic is the same as that shown previously:
public...