Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it better to have more Java classes, or have fewer classes doing more work?
    primarykey
    data
    text
    <p>I'm currently working on a game. At the moment, I have one class (the game's environment) responsible for holding collections of game objects (enemies, weapons, etc.) and doing collision-checks, calling the objects' creation routines, etc. As I've progressed with the project, I've started to wonder if I should have a more layered approach - is it better to have, say, a WeaponsManager, an EnemiesManager, and an Environment holding everything together, or to have my Environment class manipulating each object as I'm doing right now?</p> <p>It might be worth mentioning that the game objects are already fairly heavily layered:</p> <pre><code>BaseClass -----EnemyClass ----------Enemy1Subclass ----------Enemy2Subclass -----WeaponClass ----------Weapon1Subclass ----------Weapon2Subclass </code></pre> <p>BaseClass has basic object properties defined, such as position. EnemyClass and WeaponClass are fairly generic classes that define more class-specific methods and properties, such as speed for EnemyClass or damage for WeaponClass. They mostly exist so I can have fairly generic collections instead of a separate collection for each individual enemy/weapon type. Enemy1Subclass/Enemy2Subclass and Weapon1Subclass/Weapon2Subclass are the actual enemy/weapon classes, which are actually created and used.</p> <p>My Environment class stores collections of EnemyClass/WeaponClass and does the necessary manipulation by calling the game objects' methods.</p> <pre><code>Environment (manipulates EnemyClass and WeaponClass objects by iterating over their respective arrays and calling their respective methods; doesn't do any subclass-specific stuff) -----EnemyClass array ----------Enemy1Subclass entry ----------Enemy2Subclass entry ----------Enemy1Subclass entry -----WeaponClass array ----------Weapon1Subclass entry ----------Weapon2Subclass entry ----------Weapon2Subclass entry </code></pre> <p>But now I'm wondering if yet another layer of separation would be a good idea, with Environment holding EnemyManager/WeaponManager classes and the respective managers holding and manipulating their collections:</p> <pre><code>Environment (calls generic instantiation, destruction, moving, etc. methods in EnemyManager and WeaponManager; doesn't ever directly interact with an EnemyClass or WeaponClass object) -----EnemyManager (gets instructions from Environment and manipulates EnemyClass objects to carry out those instructions) ----------EnemyClass array ---------------Enemy1Subclass entry ---------------Enemy2Subclass entry ---------------Enemy1Subclass entry -----WeaponManager (gets instructions from Environment and manipulates WeaponClass objects to carry out those instructions) ----------WeaponClass array ---------------Weapon1Subclass entry ---------------Weapon2Subclass entry ---------------Weapon2Subclass entry </code></pre> <p>Thoughts? Suggestions? I've not been able to find anything about this kind of "more classes or harder-working classes" convention, so any answer is fair game, right up to and including "your model is trash, start over." Although hopefully it won't come to that. ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload