Jump to content
  • Advertisement
Sign in to follow this  
Darsin

Extending a class that's been polymorphed.

This topic is 3504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make my code more efficient. Class Entity (holds the .x mesh) Class Creature: public Entity, AI (Holds the Creatures / Characters info) Class AI (holds the basic AI functions) Class AINotControlled: public AI (Extended AI + functions for NPC's and Enemies) Class AIPlayerChar: public AI(Extended AI + functions for playable characters) is there a way to define my classes so i can hold playable and non playable characters in Creature with a dynamic AI? I've boggled my mind over this but can't come to a very definite solution.

Share this post


Link to post
Share on other sites
Advertisement
This comes across as abusing inheritance, in particular the IS A relation. Why does Creature derive from Entity? Because a creature IS A type of entity. Why should Creature not derive from AI? Because a creature is *not* a type of AI.

I would suggest using composition instead - have each creature own an instance of an AI. This solves your immediate problem, and gives you a better design.

Share this post


Link to post
Share on other sites
I had a certain type of that at one point but my colleague asked me to look into this way of doing things.

I had my suspicions this was not the way to go.
or atleast it went against my programming beliefs but i thought i'd ask before i decided not to try it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!