In: Computer Science
1) Compare and contrast the decorator and the strategy patterns. How are they similar? How are they different?
2) Why are referential equality and the instance of operators a problem for decorators?
The answer for this is as follows:
1) The stratergy pattern allows you to change the implementation of something used at runtime. The decorator pattern allows you augment(or add to) existing functionality with additional functionality at run time.The key difference is in the change vs augment. Decorator pattern can be used in a scenario where particular property is manipulated on existing objects.For Stratergy pattern, let us say you have some workflow design in visual studio.Suppose you want to open that design in 2 view. In this case, viewing is the only one activity that user going to perform,but based on user's choice the"stratergy" of viewing will get differ.
2) Referential equality means that pointers for two objects are same. Objects are contained in same memory loation which leads us to the fact that pointers reference to same object. Instance of operator is used to test whether the object is an instance of specified type(class or subclass or interface). Whereas the decorator returns a modified function or class.Therefore referential equality and instance equality are problems for decorators.