1

Simple summary of a real problem:

  1. I'm making a chess game
  2. The engine that makes the chess do the magic is its own independent code (by design, for easy implementation)
  3. I am now implementing the chess game into a game (Minecraft, but could be any mod-able game)

Problem:

  1. The code that runs the chess has classes like "Board", "Game", "Piece", "Square", etc.
  2. The code that runs the implementation, in an optimal world, would have classes with the same name, but that would make everything I'm doing in my IDE into a jungle

Question:

  • What's the best way to solve this? I'm thinking about calling the core chess game classes into something like "EBoard", "EPiece", etc., "E" being short for "Engine" /edit: i do not mean for this to be an opinion based question; "best way to solve it" as in "most logical for the IDE to digest what I'm doing"

Note:

  • This is not a "name that thing" question. It is partially, but I am also asking because I'm looking for naming conventions that IDEs can handle well. In prior projects I have made errors like naming classes in full upper case letters occasionally, and the IDE had problems recognizing that i was actually looking for a class. You get the idea.
New contributor
jaylawl is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Just to clarify, point 2 is all the code that handles the rules of chess, and point 3 is all the code that handles the "UI" of chess? – Caleth 2 days ago
  • How are the classes in point 2 different than point 3? Why do you need separate classes to implement chess in another mod-able game? What's the purpose of that separation? The difference in purpose can lead you to a good name and structure. – Greg Burghardt 2 days ago
  • Caleth & Greg: The core game is its own code to be independent and re-useable. It can be ported into anything. For instance, when developing it, i test-played it in my IDEs console via nothing but representation via ASCII. Most importantly i wanted to make sure that it just works on it's own and is neither dependent on a certain implementation nor that the code gets "tainted" by the way it's supposed to be implemented ///edit: by definition, i guess, that makes the core game some sort of "Library" :-D – jaylawl 2 days ago
3

Sometimes such classes would be named as Base- or Core- to indicate that they are to be extended in other implementations, so you'd have CoreBoard and CorePiece.

Depending on the language you're using, you could also use namespaces to distinguish between the two sets of classes. You could have a namespace for the Engine, and other namespaces for specific implementations. For example: jaylawl.games.engine.Board for the Engine's Board, and jaylawl.games.chess.Board for your Chess board.

Personally, I prefer the second option, but that may be language-specific.


If you plan to have both classes in the same scope, maybe you need better names. Perhaps instead of Board for the game engine, use something more generic, such as GameArea, to allow for future games that might not have a "board" in the same way that chess does. Maybe PlayerToken instead of Piece, GameAreaComponent instead of Square (one day you might want to have a game that has a board with a hexagonal layout instead of square), etc...

  • Thanks for your reply! Im using java. Everything is already well seperated into different packages like you mentioned in your second answer. However if were to have, like in the case you made, have two Board-classes and then used both of them somewhere together, one of them would end up showing with its full name which is the beginning of making things horrible to read – jaylawl Jan 13 at 22:10
  • The second option is ugly because you will often have to write the full namespace name. – user253751 2 days ago
  • @jaylawl If you plan to have both classes in the same bit of code and you don't want to prepend one name with the full qualifier, then maybe you need better names. – FrustratedWithFormsDesigner 2 days ago
  • @user253751: The second option might become ugly in case one will often have to write the full namespace. It depends on how separated those modules are. – Doc Brown 2 days ago
  • @DocBrown well the question is about one system with two sets of classes based on the same domain. Not two separate systems. If it was two separate systems that didn't talk to each other, namespaces would work. – user253751 2 days ago

Your Answer

jaylawl is a new contributor. Be nice, and check out our Code of Conduct.

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.