Your objective
Over the course of this chapter, we will be looking at a few more important concepts and principles that can make our programs better. Here is an outline of what we will cover and your tasks for this chapter:
- Learning why using
switch
statements can be bad - Learning the Dependency Inversion Principle
- Learning the Factory Method pattern
- Building a Component, Stage, and Object Factory
- Improve your Factories by using templates
The trouble with switch statements
When first learning to program, simply understanding the grammar of the language is very difficult. Often, new programmers focus on the syntax of a function call or for
loop and they don't even think about making reusable, maintainable code. This is partly because they jump into the coding without planning anything out. This is true for games as well. Often, new programmers want to get straight to writing the game and they forget about things such as user interface and pause menus. Things such as the window resolution, enemy placement...