Home  /  Questions  /  Question

50   50
Aug 31, 2011

Difference between Proxy Pattern and Observer Pattern

What's the difference between the Proxy Pattern and the Observer Pattern?  Does the Observer provide more flexibility to handle events when compared to the Proxy?

Thanks for your help

50   50
Sep 01, 2011
The Observer Pattern is used by a publisher object to notify subscriber objects with information. The publisher object does not know the subscribing objects - except that the conform to a certain subscriber interface. This is a very flexible pattern for distributing events, since those that wants to listen on certain object has the power to do so without changing the code of the publishing object.

The Proxy Pattern is used for wrapping a kind of special object with 1 or more other objects. Either because you don't always have the wrapped object or because it needs to be managed in a certain way that can be simplified via the proxy object(s). This is kind of a way to exchange the API of an existing class with a proxy class. We are not just talking events here, but whatever kind of functionality to define via the proxy object instead of the real object.

I hope above makes sense for you as well :)

Kind Regards,

Keld Ølykke