Jump to content
  • Advertisement
Sign in to follow this  
LonelyStar

Polymorphismus problem

This topic is 4831 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

Hi everbody, For an online game, I have a player class for the server ("ServerPlayer") and a player class for the client ("ClientPlayer"). Now, these two classes share some functionality, that's why tere is a base general base class "Player: Player -> ClientPlayer | v ServerPlayer So far so good. Now, i.E. create the library of the base functionality of my game (which includes "ServerPlayer", "ClientPlayer" and "Player") to allow other people to use it and make mods (or simililar games). These people can create more functionality on the server side by deriving from "ServerPlayer" and more functionality on the client side by deriving from "ClientPlayer". But what if they want to add some functionality used by the server and the client? Naturally that would have to be added to the "Player" class, before "ClientPlayer" and "ServerPlayer" are derived. How would you solve this problem? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Have you studied policy classes at all?

Basically what you have with policy classes is pluggable behavior.

If you're up on template metaprogramming, it might be something for you to check out.

not sure how good this article is... but check out Andrei Alexandrescu's writings for more information.

Share this post


Link to post
Share on other sites
Of course, if you'd prefer to do things at runtime (and the extra flexbility often is called for), you may want to think about object composition instead.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!