Monday, July 11, 2005

State and Strategy identical ? How about Bridge ??

Did you know that State and Strategy patterns are identical in their structure? Why are these patterns given different names? Its the intent that matters in design patterns than the structure of the pattern per se. Here the intent of both the pattern is different. The State pattern alters and objects behavior when its state changes whereas the Strategy pattern encapsulates varying algorithm which simply also means varying behavior of a type. State is dynamic whereas strategy is bind once static pattern.
Some architects / developers may go to the extent of classifying the State and Bridge also alike but I do not think so because Bridge pattern decouples the abstraction from the implementation. Here the decoupling of abstraction from implementation does not mean in terms of a class but as an objects behavior. Understanding this pattern in terms of an object makes it easier to understand and use it. In-fact this pattern is very easy to use in .NET since the Garbage collection is handled by the CLR and hence the implementation object can be destroyed when its abstraction is destroyed. This happens because when the Garbage Collector sees broken reference to an object it is automatically collected for garbage collection. Whereas languages like C++ have to keep a reference count and then destroy it based on the counts like in the COM world.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home