Skip to main content
gamedev.net
🔒 Locked

Polymorphismus problem

Started by LonelyStar Aug 26, 2005 at 5:29 PM 1 replies 500+ views
Original Post
LonelyStar
LonelyStar
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!
Verg
Verg
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.

Zahlman
Zahlman
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.

Topic Locked

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

Sign in to reply to this topic.