Game developers have ideas for new games all the time. When you’ve got your next game in mind, you decide what your UI will look like and what features your game will have, but how strongly do you really think about the architecture of your code?
So you can easily say “I don’t care. Just let me go live ASAP!” but did you ever think of the implications of that? How will you maintain your code? How will you make quick changes? How will you extend your game for more features easily?
MVC = Model View Controller
MVC is one the most important and well known architecture patterns out there. It’s been known for years and used by a numerous number of apps on all possible platforms. If you don’t know what MVC is you can see this video and get a good sense of what you missed all these years.
The main goal of MVC is to make developers’ lives easier. If you don’t use a structure like MVC for your game, your code will most likely end up looking like a big mess, otherwise known as “spaghetti code”. Developers who don’t separate the display code from the game logic find that once their game app becomes a bit more complex, they have a hard time trying to refactor their code.
Messy code can lead you to many problems:
- Finding and fixing bugs is more difficult.
- It will be harder to add new features.
- Changing existing features will take longer that you thought.
MVC to the rescue
MVC will help you solve all the above issues and more:
- MVC makes the code of your game both easier to write, and easier to understand.
- With MVC you will write less code.
- Your code will be more flexible and modular, making it quite simpler to update in the future. If at some point in time you’ll want to change things in your game, MVC will give you the delight of making absolutely no changes in the model. The only change you’ll have to make is to replace the old view with a new one or just change a specific controller.
- Adding new features will also be easier because your code is modular with MVC. You will always be able to add views to your game and connect them to your existing controllers. If you need to add more logic you can just create another controller and connect it to the others and to your existing models. As easy as “Plug And Play”.
Is there any reason not to use MVC ?
If you decide not to use MVC, it can be because of either of two reasons:
- When you began to write the code for your game, you didn’t foresee how MVC will help you. The result will be that you will realize your mistake later on when your code gets messy.
- Or, your game is extremely simple and you really have no use for design patterns.
To sum up, MVC helps you write clearer code, which is much simpler to update and maintain, and using it will almost always save you an awful headache in the future. Whether you choose to work with MVC or not, once your code starts looking like a game, feel free to return to SOOMLA for your in-app purchasing needs!