How far do I take Composition?
Posted
by
whiterook6
on Game Development
See other posts from Game Development
or by whiterook6
Published on 2012-04-05T05:06:57Z
Indexed on
2012/04/05
5:44 UTC
Read the original article
Hit count: 228
architecture
(Although I'm sure this is a common problem I really don't know what to search for. Composition is the only thing I could come up with.)
I've read over and over that multiple inheritance and subclassing is really, really bad, especially for game entities. If I have three types of motions, five types of guns, and three types of armoring, I don't want to have to make 45 different classes to get all the possible combinations; I'm going to add a motion behavior, gun behavior, and armor behavior to a single generic object. That makes sense.
But how far do I take this?
I can have as many different types of behaviors as I can imagine: DamageBehavior, MotionBehavior, TargetableBehavior, etc. If I add a new class of behaviors then I need to update all the other classes that use them. But what happens when I have functionality that doesn't really fit into one class of behaviors? For example, my armor needs to be damageable but also updateable. And should I be able to have use more than one type of behavior on an entity at a time, such as two motion behaviors?
Can anyone offer any wisdom or point me in the direction of some useful articles?
Thanks!
© Game Development or respective owner