Imagine you're building a Starcraft, and you want to model a Hydralisk class.
Hydralisk can...
- Walk around
- Attack other units
- Count kills
- Have states: Hold, Attack, Move, Patrol
- Burrow
- Morph into Lurker
- Has some fancy AI
So Hydralisk has a lot of features. Putting all of these features into single Hydralisk class is clearly a violation of Single Responsibility Principle, which we all want to avoid.
Note that our problem here is not because given features are complex, but because there are a lot of them. Pathfinding and AI can be modularized, but Hydralisk still has to know how to use all of those modules. Even more, These features are tightly coupled. Hydralisk needs to know whether he's burrowed or not to check whether he can attack or not.
So, how can I decompose a giant Hydralisk object?
Aucun commentaire:
Enregistrer un commentaire