Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Diamonde opened this issue Jan 7, 2015 · 0 comments

Comments

@Diamonde
Copy link

Diamonde commented Jan 7, 2015

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...
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant