Learn Design Pattern: Proxy Versus Chain of Responsibility. These two design pattern seems similarity somewhere or others. Structurally both are same but intent of both are different.
1. Proxy Design Pattern
control Access to it.
What is proxy?
Let me explain the similarity and differences of chain of responsibility vs proxy. For more details, visit Proxy Design pattern
It’s an intermediary between a client object and the target object. responsibility wise, It receives a call from client object and forwards them to the target Object.
2. Chain of Responsibility
allows an object to send a command without knowing what object will receive and handle it.
The Chain of Responsibility (CoR) design pattern allows an object to send a command without knowing what object will receive and handle it. The request is sent from one object to another making them parts of a chain and each object in this chain can handle the command, pass it on or do both.
The example of Chain of Responsibility is Filter Interceptor in core J2EE design pattern. In the Filter, there is a chain and no one knows about another if any filter does not fulfilled then request to the next filter if fulfilled then return from the same filter to the caller. There could be a possibility that no one fulfilled the request. Another example of approval of Purchase Order in workflow by Manager, Sr. Manager, Director, AVP, VP, COO etc.. Every person has a limit to approve if the limit exceeds, send a request to the next in the workflow.
3. Key Points Proxy versus Chain of Responsibility
I tried to cover the key difference between proxy and Chain of Responsibility (CoR) design patterns.
- Proxy represents a single object while Chain of Responsibility can have many objects.
- Proxy first received the request from the client but never processed by the proxy object, while in Chain of Responsibility it processes by the target object. In the Chain of Responsibility, an object that received the client request could process the request first.
- Proxy always forward client request to target object while in CoR forward the request in the chain only current object can not process the request.
- In Proxy response to the request guaranteed provided communication link between client and server location working while in CoR Response to request is not guaranteed. It means the request might reach the end of the chain but the request could not be processed.
I hope you enjoyed this post of proxy vs chain of responsibility design patterns, and you can visit design patterns tutorial for more details
Please write your comment to improve this post. Happy learning 🙂