Alex Rivera | Logout

Difference between Strategy pattern and Delegation pattern

Asked 2009-08-03T21:55:52.747
27

What is the difference between Strategy pattern and Delegation pattern (not delegates)?

Edit
Report

1 Answer

2

Here's a thought:

Delegates mimic the delegating class (at least as I've used them, not sure if that's the canonical way or not but that's how I usually do it). So basically, if I have a class that has multiple entry points (methods) and I want to change the implementation at runtime, I would create delegates the implement the same interface.

If, on the other hand, I had one part of a class that I want to be able to interchange at runtime, I would create Strategy classes with a single method interface (eg. executeCalculation) and make it an aggregate component of the containing class.

So in summary, a strategy encompasses a single behavior, delegates implement a set of behaviors, and you could use delegates to implement strategies.

answered 2011-02-23T18:31:55.967

Your Answer