Skip to main content

Turn based game class design [Resolved]

I wrote abstract base for some turn-based games (like chess or tic-tac-toe) and wrote game based on this base. And I stuck with choosing how to design class hierarchy. Here is two variants for wich I came up: Static class wrapping And here is second screenshot (it is too long to post here as image)

In first variant all classes in different namespaces (or I can move them to one namespace). In second variant all classes separated with static classes and they all in one namespace. First variant's diagram looks better, but I think that second is more correctly. How better to design this structure?


Asked January 11, 2017
Posted Under: Programming
47 views
1 Answers

Well, first things first :)

You don't really need to mess with namespaces on your case. Namespaces are more of an organizational tool than anything else. Most of the time, tho, you can just leave this up to Visual Studio. The IDE is really smart and will figure out the namespace name you should use based on the folder structure you have on your project.

Next, avoid using nested types. Nested types are OK for a small set of necessities, not on your case. You don't really need the "Base" class - just promote your nested types to regular classes and you're good to go.

Also, you don't need for those non-tool classes to be Static. They look more things that would belong to a single instance of a board than to the entire app. What would you do if you wanted to have two chess matches going side by side? As a rule of thumb, leave the "globalness" of the static keyword for things that should really, really be global. Your "tools" classes seem like likely candidates for the static keyword, so you can leave that there.

As an alternative, you can look up Dependency Injection. While it seems like a big, scary concept, is something so simple most of people where already doing it anyway by hand way before DI frameworks were a thing. Don't be tricked, tho - Dependency Injection doesn't need to, and sometimes should not, be used by means of a DI Framework. You can very well do it by hand without issues and without the added complexity of a DI Framework.


Answered January 11, 2017
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA