java - How to administrate Strategy Pattern behaviors at runtime? -
i'm reading head first design patterns book when doubt came head.
in first chapter, studying strategy pattern taught make interchangeable classes. according picture below:

my question: if want make desktop application visual interface , let users have more privileges others administrate ducks , behaviors? so, example create flyrocketpowered behavior @ runtime. how can achieve this?
i mean, these behaviors weird me represented classes, because can't see how make them editable @ user level, every time flybehavior, quackbehavior or duck subclass needs created/deleted/changed users have ask me modify source code creating/deleting/changing classes, not want, need more developer-independent.
edit
say want make screen add fly behavior (just add, not edit, not remove), there have 2 fields, first behavior name, second content printed when fly() method called.
by editing source code creating class this:
public class flyrocketpowered implements flybehavior { public void fly() { system.out.println("i’m fl ying rocket!"); } } what need make @ user level?
firstly i'd love book. it's favourite programming book.
to question: think missunderstood strategy pattern little bit ;) goal not enable users create new behaviors @ runtime. pattern, can give 'admins' panel give duck available behavior. behaviors still generated @ compiletime. can interchange behaviors @ runtime
additionally, funfact: totally possible let 'admin' create new behaviors @ runtime. take @ java compiler api. if think doing so, remember how big security hole , how unimaginable stupid worst case customer is.
Comments
Post a Comment