Is Java's exception handling mechanism an example of the Chain of Responsibility design pattern?

后端 未结 1 423
小鲜肉
小鲜肉 2020-12-19 11:11

I have been reading about the Chain of Responsibility design pattern which basically allows a decoupling between the sender of a request and receiv

相关标签:
1条回答
  • 2020-12-19 11:40

    You are right. Exception handling in Java is based on Chain of responsibility pattern In this pattern:

    1. Sender will not know which object in the chain will serve its request
    2. Each node in the chain may decide to serve the request --> catching an exception and
      wrapping it with an Application specific exception
    3. Each node can forward the request --> throwing exception to the immediate caller
    4. None of the node can serve the request --> Leaves the job with the caller

    Hence, Exception handling is a Chain of responsibility pattern

    0 讨论(0)
提交回复
热议问题