Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# Alternative to Multiple Inheritance

Started by Gf11speed Oct 23, 2008 at 8:15 PM 2 replies 2k views
Original Post
Gf11speed
Gf11speed
Since C# does not support multiple inheritance I was wondering if anyone knew a good way to do the following. Basically I have 3 classes, and I'd like to use functionality in class 'PlayerInGame' from both 'Player' and 'SceneNode'. What's the best way to do this? I'd prefer not to include either of those classes IN PlayerInGame if possible. Player SceneNode PlayerInGame : Player, SceneNode Seems like a fairly simple problem, I'm just a C++ programmer having a C# brain freeze tonight. Thanks.
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Hodgman
Hodgman
Well, In C++ I'd recommend that you just change your "is a" relationship to "has a":
struct PlayerInGame{  Player    player;  SceneNode sceneNode;}
smitty1276
smitty1276
This design doesn't make much sense to me. By what logic can something *BE* both a Player and a SceneNode? Maybe a better approach would be the following, if this idea is really given such prominent treatment that it deserves its own type:

SceneNode
PlayerSceneNode : SceneNode ----> has a Player

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.