One alternative that avoids lengthy switch statements all over the program would be to create adefine inside your Skill interface and a Skill factory which constructs skills according to specifications provided elsewhere (suchadditional components that define its behavior. These components would be implementing an interface as a JSON filewell.)
With thisFor example, creating a skill may be done simply by somethingall skills might contain an attack behavior, which could look like:
IAttackBehavior attackBehavior;
Creating an actual instance to put inside the (forgive my C++ syntax but it shouldattackBehavior can be simple enough to understand)done via a factory method, for example:
ISkill skillattackBehavior = SkillFactoryattackBehaviorFactory::createSkillcreateAttack("Fireball" /* relevant parameters here */ );
where createSkill() isThe parameters can be supplied by a staticJSON file as well. You would probably see some switch statements inside this factory method of the SkillFactory class, but they would be contained to one place.
Now that its behaviorOnce your attackBehavior is definedimplemented, using a skill may be done likeyou could call it with:
skillmySkill.attack(enemytarget); // calls mySkill::attackBehavior(target)
Of course, this really depends on the interface you decide to use for skills. If you wanted to, you could even break a skill into separate components and use a factory method to provide these as well!
Some ofI'm not sure if this idea's benefits, along with its elegance, are that you can now delegate skills quite easily around the program, and additionally may change them at run-time.
This is the gist of the ideaanswers your question perfectly, but hopefully it provides some inspiration forso let me know if you to work withhave any questions.