1

Can I implement Strategy Pattern using AOP. I would like to either 1. Override the default algorithm 2. Or Would like to dynamically select any of the given algorithm.

Thanks,

user667022
  • 351
  • 3
  • 13

1 Answers1

1

Look at "AspectJ Cookbook" by Russell Miles. It provides implementation of almost all classical design patterns from the point of AspectJ's view. Here is direct link to strategy pattern http://books.google.com/books?id=AKuBlJGl7iUC&lpg=PP1&pg=PA230#v=onepage&q&f=true.

alehro
  • 2,198
  • 2
  • 25
  • 41
  • Thanks for the link. I am trying to implement Strategy pattern as suggested in the cook book. But I am confused where do I do the run time selection of Strategy. As per the book the method setConcreteStrategy is in the abstract Aspect StrategyPattern. So from where can I invoke it – user667022 Sep 05 '11 at 13:31
  • @user667022 Invoke it from the place where you are associating contexts and strategies. Something like this: SortingStrategy.aspectOf().setConcreteStrategy(context, strategy). Also look at the sequence diagram on "Figure 19-25" from the aforementioned link. – alehro Sep 06 '11 at 07:46