官术网_书友最值得收藏!

Understanding the chain of responsibility pattern

The purpose of the chain of responsibility design pattern involves senders and receivers. Specifically, the chain of responsibility design pattern calls for the decoupling of the sender and receiver. Objects can be sent to a series of receivers without the sender being concerned about which receiver handles the request. The request is sent along a chain of receivers and only one of them will process the request. Let's look at some examples of this.

Consider a large customer service agency that handles thousands of incoming emails each day. Instead of having a person or persons manually review each one to determine which department should process the email, we can write a Java program using the chain of responsibility design pattern to send the emails along the chain so that they are processed by the appropriate department.

Another example is a call center. Many call centers now ask the caller to briefly describe what they are calling about and then the caller is placed in a queue. The caller's brief descriptions are recorded and then analyzed for key words. The calls are routed along the chain and then processed by the appropriate agent. In cases when an agent receives a call that is not appropriate for them, say it is regarding billing and the agent handles shipping, then the call can be sent further down the chain.

We will further explore a third example that involves incoming emails to a university. The university has several functional areas and wants to ensure the emails are routed to the appropriate team. We will look at the use case, UML class diagram, and the source code necessary to implement the chain of responsibility design pattern for this scenario.

主站蜘蛛池模板: 韶山市| 山阴县| 潼南县| 保德县| 宣汉县| 绵竹市| 宿迁市| 石嘴山市| 霍邱县| 尼勒克县| 花莲市| 莱芜市| 海兴县| 冕宁县| 辽宁省| 洪雅县| 长白| 霍邱县| 建阳市| 玉树县| 讷河市| 大石桥市| 洮南市| 姜堰市| 泸溪县| 正安县| 错那县| 鹤庆县| 简阳市| 济源市| 瑞昌市| 鸡泽县| 高雄县| 慈利县| 将乐县| 河曲县| 桂阳县| 田林县| 沁源县| 长白| 三明市|