Reputation: 3108
I am developing a game. Instead of creating a class for each game entity I created an entity class and a feature class. Entity objects keep location, name, id and a list of entity features. I have bunch of feature classes derived from feature like movefeature, fuelfeature, displayfeature... If I need a moving entity I add movefeature to it. If it is a vehicle and burns fuel, it gets fuelfeature. Entities shown on screen have displayfeature and so on.
This probably is a design pattern and someone invented it before me. My question: is this method a valid pattern and what it is called?
Upvotes: 2
Views: 115
Reputation: 14116
What you describe is really just composition and favoring composition over inheritance, which is usually a good idea.
As for patterns, I'd say you prolly use a lot of them, conceptually at least if not strictly correct implementation-wise. Take a look at the patterns listing and you'll be able to indentify a bunch yourself just by the name and short description. By what you say I'd guess you might be using the following:
See, patterns are like vegetarian thali, you just end up with mix and match of some, aware of em or not.
Upvotes: 1
Reputation: 5079
It can be more than one pattern depending on how you design/implement them. I can see some of these possible patterns in there:
Upvotes: 0