lundi 28 mars 2016

If In Proxy Pattern we have interface instead of real Subject in Proxy class is it equivalent to Decorator Pattern

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

enter image description here

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.

enter image description here

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

enter image description here

Aucun commentaire:

Enregistrer un commentaire