game-programming-patterns icon indicating copy to clipboard operation
game-programming-patterns copied to clipboard

Design question: Is Subclass-sandbox an overcomplicated strategy pattern?

Open Diamonde opened this issue 10 years ago • 0 comments

What seems complicated is initialising concrete Superpowers with the necessary resources (playSound(), spawnParticles(), etc) in section "How does the base class get the state that it needs?".

I wonder if the Strategy pattern could be used instead of the new pattern? Let me explain briefly what I mean and perhaps you could elaborate on the similarities and/or differences of both approaches: Say you have an interface Superpower -

class Superpower{
public:
  virtual void perform(SuperpowerResources* res) = 0;
};

Any new super power you would create then realises the interface. Following, the SuperpowerResources class is separately initialised, containing the necessary resources the super power implementations need -

class SuperpowerResources{
public:
  void move(double x, double y, double z)
  {
    // Code here...
  }

  void playSound(SoundId sound, double volume)
  {
    // Code here...
  }

  void spawnParticles(ParticleType type, int count)
  {
    // Code here...
  }
};

Diamonde avatar Jan 07 '15 20:01 Diamonde