문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top