4 ms·
Agree with pwim that 150 subclasses is way too many. OO Principal Favor Composition over Inheritance easily kicks in here. But even with fewer subclasses we sti
by ericHosick 16y ago
Agree with pwim that 150 subclasses is way too many. OO Principal Favor Composition over Inheritance easily kicks in here. But even with fewer subclasses we still have to define the likes/dislikes of N monsters with N-1 other monsters. Further, every time a new monster is added, N monsters like/dislike logic has to be updated.
Maybe we are looking at the system/problem from the wrong perspective?
Maybe the likes/dislikes between monsters isn't actually so arbitrary. Perhaps, it is the characteristics of one monster that other monsters don't like or do like. If this is the case (which makes sense as in the real world we judge other things based on characteristics and behavior), then the like/dislike behavior can be encapsulated.
Further, using something like Strategy pattern, you can come up with a set of algorithms that define the likes/dislikes between monsters. That way you can compose that specific behavior of a monster at run-time further reducing your class count.