mardi 23 décembre 2014

When would it be appropriate to start a project with the proxy pattern?

For the proxy pattern, we have:



  • An interface (or abstract class)

  • A subject that implements the interface and does the work

  • A proxy that implements the interface and delegates the work

  • The client gets an object (either the proxy or the subject) that implements the interface


If you want to modify existing code, it makes sense (to me). For example, say I have clients that use the subject. In a future iteration, I want to add a security layer, so I pass the client a proxy that does the security checks before delegating the rest of the work to the subject.


Is there a scenario where you would want to start a project using the proxy pattern? It doesn't feel like anything is gained if the "proxy" object implements the same interface as the subject. I can give the client an object that delegates the work appropriately, and not be forced to implement the "proxy" with the same methods as my subjects.


Aucun commentaire:

Enregistrer un commentaire