In my flutter idle game, I use composition root class gamesession, but I consider making…
- User
In my flutter idle game, I use composition root class gamesession, but I consider making some more dirty classes that instantiate multiple game objects, like my class afk that Instantiates enterprises and income upgrades. Is it a good idea?
- Assistant
Deciding whether to create a separate class for instantiating multiple game objects in your idle game depends on various factors. Here are a few considerations:
-
Separation of Concerns: If the instantiation logic for enterprises and income upgrades is considerably distinct from other parts of the game session, creating a separate class (such as "afk") can help better organize your code and ensure each class has a single responsibility.
-
Reusability and Extensibility: If you anticipate the need to reuse or extend the instantiation logic for enterprises and income upgrades in other parts of your game or potentially in other projects, creating a separate class can facilitate this.
-
Code Maintainability: If having a single composition root class (like "gamesession") with all the instantiation logic makes it hard to understand and maintain the code, splitting it into smaller, focused classes can enhance readability and modularity.
-
- User
Which seven things to avoid when writing unit testable code
- Assistant
When writing unit testable code, there are several common mistakes to avoid. Here are seven things to keep in mind:
-
Tight Coupling: Avoid tightly coupling your code with external dependencies or implementation details. Use interfaces, dependency injection, and abstractions to decouple components and make them easier to test in isolation.
-
Global State: Minimize or avoid using global state as it can lead to unpredictable behavior and make unit testing challenging. Instead, isolate stateful components and use dependency injection or other techniques to manage their state.
-