Could you help me to find a solution to my problem?
I have a class that represents an entity (I will call it "Entity") I would like to dynamically add methods to my Entity according to different criteria.
For example:
If $_POST['TYPE'] == 'typeA', I would like to add following methods:
- method1()
- method2()
- method3()
- method4()
If $_POST['MODE'] == 'modeA', I would like to add following methods:
- method5()
- method6()
- method7()
The problem is that there will be a lot of possible methods and and if I add all of them to my class, I'm affraid that my class becomes too big. I also would like to avoid editing my class every times a new situation arises.
I firstly thought about having a class by case but I have too many cases (about 5 criteria and for each one 6 or 7 possible different values) so about 50 or 60 different cases in full.
So what is the best solution to do that?
Should I add all possible methods to my class?
Should I use inheritance and create all possible kinds of objects (Type1Mode1Entity, Type1Mode2Entity, ...)?
Do you know a design pattern (decorator?) to do that?
Ben