[quote name='No Style Guy' timestamp='1299095713' post='4781112']
By your logic, if i view a game as an object who is a singular object with attributes such as players and terrain and game mechanics and physics, then why not just make one God class that inherits everything from everybody and has no composition? Does that sound like fun to manage?
XD if you view it that way, then go ahead. Personally I think it's much more believable than an enemy "is" both himself (the AI) and his graphical representation (his body) than your extreme. Look, I'm even using "is". That's the problem with the principal. It's opinionated. If I say something IS something and you say something HAS something then people get in this big argument. Just forget the damn principal and program it logically. >.< If you see the player as BEING the paddle, use inheritance. If you see the player as HAVING the paddle, use composition. I don't care.
[/quote]
Precisely. My God class example used "is-a" because I was framing it to fit
your view. I personally think it makes more sense that "A game
has-a terrain,
has-a player,
has-a Physics system, etc" (as per my exmaple) or even "A player
has-a Body (sprite) and
has-a Brain (AI)" but you seem to think it should be "A player
is-a Body and
is-a Brain" (as per your example).
Regardless, I'll conceed that the
is-a and
has-a idiom can be subjective (or rather, both can work), so I wont argue that further.
The problem is that there are characteristics of each approach that are tangible, undeniable facts. If you have an inheritance tree where the current object has inherited attributes, either directly or indirectly, from, say, 10 different classes, the exact origin, purpose, and usage of those attributes is undeniably confusing. If the same current object was a composition of those classes, it would be (nearly) explicit where those attributes came from, what they affect, and why they're there.
I've lost count of the number of times where I've been trying to extend a class that seems to be modifying an undescriptive member variable (say, "count") which is not declared in the immediate class's header. I then backtrack through each of his multiple inherited base classes for somebody with a "count" member variable. If he had just had MyObject.baseclass.count, I would have had a lot less headaches.
Composition: easy maintainability, re-use, good cohesion and low coupling
Inheritance: less code, but poor {all of the above}
That is the basis for this argument, not opinions about how you view relationships of objects.