 | Hi , fairly new to OO design. Trying to solve a problem:
problem: I want to make a large number of different monsters. what makes monsters different from each other is their 'abilities'. These could such things as carrying a weapon or magic item that allows them to perform an action, or something like an intrinsic resistance to attack with fire, or a temporary ability ability granted by a spell cast on them.
* I want to be able to define different monster types and different ability types using as little memory as possible (mobile phone platform) - a hard coded table of abilities and then another table of monsters that lists which ability each monster has. Some sort of factory will have to create the monster given an index into this table. Thats not the hard part.
* I want to be able to add new monsters and new abilities to the table without changing the inteface of the monster and ability class. I think this is the hard part.
solution: At first thought, the decorator pattern seems right, but because abilities can come and go all the time, it seems to be unweildy.
I think what I want to happen is that every time the monster has to do something that involves its characteristics which may be modified by abilities (such as fire resistance), or it wants to perform an optional action that an ability may bestow it with (such as hit something with a weapon), it should interogate its entire list of current abilities to see if they impact on that charicteristic or action. But how to structure that process in my design?
Is there a particular pattern I should be looking at?
thanks,
Steve
|
|