Architectural patterns for the game

So, I have a solution that contains several large projects that I am trying to break down into smaller projects with more isolated responsibilities. This is a game, but I'm mostly a LOB developer, and I think the principles are probably universal, and I think I could learn something here.

Dependencies in some objects are too closely intertwined, and I hope for some help on how to unravel them. Or maybe some kind of pattern or abstraction that can make them more manageable.

Ares.Core.World has classes in itself, such as Creatures, Items, etc. They all inherit from Entity, which knows which cell on the map it exists. This is achieved by referencing Ares.Core.UI.MapControls.MapCell ... And you can see that the wires are already crossing.

Ares.Core.UI.MapControls contains Map and MapCell, each of which contains lists of creatures and the elements that they contain. MapCell also inherits from Ares.Core.World.Entity, since it allowed us to solve several early problems very elegantly - for example, all objects have an inventory.

I would like to find a way to separate UI and World into separate projects ( Ares.World and Ares.UI ), as the user interface and the comprehensive world should probably be separate issues. But, as you can see, as of now, the two projects had to link to each other, and circular links were not allowed.

I am wondering if there are any architectural patterns that can help in this situation. Thanks!

+4
source share
3 answers

So, your lessons of the world are creatures, objects, etc. - they all need something from MapCell.

Can you intelligently create an interface (or several) that represents what the World Organizations need? So, so that Entities only need to implement this interface?

This will be the first step towards a decoupling of the two. Perhaps it’s obvious that not one of the method signatures or properties of this interface can include classes from a user interface project. It should be defined with standard types or custom types in the library, both with reference to World and UI (e.g. Ares.Core).

Then, in the UI project, define the implementations of the interface (s) that encapsulate MapCell and provide what is needed for World Entities.

Use your IoC to provide implementation where it is needed, depending on how you get MapCell, you may also need a layer on Factory.

It is difficult to be specific without any details of your specific needs, but I think that this approach as a whole should be workable.

+2
source

There is nothing wrong with the fact that classes in different namespaces interact on a fine-grained level. Separation of problems can be performed at the level of access protection (public, secure, closed, etc.). You can break down your project into subprojects, either logically or structurally, by applying any additional organizational constraints that you think are relevant.

Some strategies may be:

  • Structurally separating logic, where each silo is in its own namespaces and interacts only through high-level interfaces.
  • Logical separation when an assembly (or asms set) becomes a logical project that can span multiple namespaces. Interaction can be done through interfaces, but also by carefully considering member access.

To unravel them, try to see the project from different perspectives. What may look like complete mess from one POV can really look elegant from another POV. If you find that there is actually a reasonable logic to their class structure, all that is probably needed is to start dividing bits and pieces into different assemblies with minor changes in namespaces. If you think this is chaos, well, your work is cut for you: -D

+1
source
  • The design of Divide and Conquer suggests that you have to separate the interface and the main component.
  • The logic of the game should be part of the main module instead of the user interface.
  • The user interface must have a graphical interface and an action interface or an object behavior interface and is implemented using the main module.
0
source

All Articles