1

I've created a small hangman game, very simple. I currently have 3 classes: HangmanStart(start menu), HangmanUI(main game window) and HangmanMain(methods).

But I would like to know when you should have more/less classes and when I should break them down even further.

Currently I have getters/setters and handle data/manipulate in HangmanMain, but it's getting quite long.

When should you break down classes to create smaller classes even when they handle the same input? Or should I have one class for getter/setters, one for win/lose condition, one for changing string etc?

  • 6
    This might be better suited for SoftwareEngineering for general principles, or (with actual code) for CodeReview. (Also, (a) welcome, (b) asking for 'reading material' is asking for getting your question instantly closed, (c) English is very good, and (d) have a great day, too.) – tobias_k Aug 24 '20 at 10:34
  • 5
    That is too broad of a question. There are entire books (and quite a lot of them) written about application design, how big classes should become, how much logic they should encompass, what their responsibilities should be, what patterns they should use to talk to each other, etc. – luk2302 Aug 24 '20 at 10:34
  • Sorry, I only meant to get maybe some kind of reading material so I can create my own understanding of when to create new classes. Since this question is so broad, it's hard to really search for it. Especially when you have a limited vocabulary in English. But thank you all for the help anyway! – Frutty Personal Aug 24 '20 at 10:45
  • [Clean Code](https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882) should get you started. – luk2302 Aug 24 '20 at 10:46
  • 1
    Essentially, try to go for "separation of concerns" aka "one class should do exactly one thing, and do just that one thing. Everything regarding that *thing* should be in that class". – Shark Aug 24 '20 at 10:50
  • Meaning the following: Game logic can have many "helper" classes taking care of certain aspects of the game, where the game logic composes and coordinates them (aka WordValidator, WordInputReader/Parser). Game UI can have many "helper" classes regarding UI (StartMenuHelper which builds the "start menu" UI, GameScreenHelper which builds the "game screen" UI) and lots of utility classes (VictoryConditionValidator, WordInputReader, WordInputParser, WordValidator, mentoned above) – Shark Aug 24 '20 at 10:55

0 Answers0