Sign in to follow this  
Darsin

Extending a class that's been polymorphed.

Recommended Posts

Darsin    122
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
swiftcoder    18437
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
Darsin    122
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this