1

I am making a game and have been following examples which use the MVC architecture pattern. I am now trying to get my head around how this would fit in with a 3-tier architecture. From what I have gathered so far:

  • MVC and 3-tier are separate ideas and are compatible
  • MVC has a triangular communication structure, whereas 3-tier is a stack
  • MVC can be used within the 3-tier structure, with the MVC parts contained in the UI layer as in the diagram:

MVC in 3-tier

My Model for the game contains all the classes describing the abstract game world - all the items, characters, their positions and velocities in the world, the score, etc.

But now what would constitute the business tier below this? As this is all the things I would normally associate with the business layer.

Should the diagram in this case perhaps show the View and Controller in the UI layer, with the Model contained in the Business layer below them?

7

Quoting Martin Fowler's famous article:

In MVC, the domain element is referred to as the model. Model objects are completely ignorant of the UI.

So the answer is, the "Business Logic" clasically belongs in the model layer. (Which, itself can consist of arbitrarily more stuff, definitely not just anemic domain objects). You putting your domain objects there seems correct to me.

That said, the MVC architectural pattern rarely fits anything practical, let alone a game. Games have different architectural problems and MVC does not address them in practice.

You should focus on separation of concerns and structuring your logic in a modular way, focusing on a form of separated presentation that fits your problem. MVC is one of the most overused terms in UI programming and people tend to use it for anything that does separated presentation. Thinking about "what MVC" is is not very useful. Focus on your architecture rather than a specific pattern.

  • 1
    Definitely upvoting this. I've tried writing games in "classical" patterns and been sorely frustrated with the result. I think the whole N-tier thing sometimes still has some analogues, but one interesting thing about games vs. say the next business application is that the UI is often extremely custom and the view layer is thick and heavily dependent on lots of logic vs. more form-like. The note about separated presentation is crucial too and may not be evident up front: the ability to manipulate game-state without the UI may only come up later as AI is developed etc. – J Trana Apr 28 '14 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.