Proxy pattern delegates the request to the Real subject after doing some additional processing like applying checks if to process the request.
It has class diagram as below
Proxy class has a direct reference to the concrete Subject.
Decorator Pattern enriches the behavior of the component [like proxy it also does some additional processing and delegates the operation to the real component]. The class diagram of this pattern is similar to Proxy pattern with only difference being it has the reference to the interface of the component.
Having concrete real subject in Proxy class makes it difficult for unit testing as Classes should only be dependent upon interfaces and not the implementations. My Question is if Proxy pattern also has the reference to the interface exposed by the Real subject then will it be equivalent to the Decorator pattern. In such a case the class diagram of the proxy pattern will also become as below
Aucun commentaire:
Enregistrer un commentaire