lundi 11 septembre 2017

Decomposing object that can do a lot of things

Imagine you're building a Starcraft, and you want to model a Hydralisk class.

Hydralisk can...

  1. Walk around
  2. Attack other units
  3. Count kills
  4. Have states: Hold, Attack, Move, Patrol
  5. Burrow
  6. Morph into Lurker
  7. 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