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

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.

主站蜘蛛池模板: 常德市| 老河口市| 台中市| 淳化县| 宁陕县| 阿城市| 玛沁县| 田阳县| 邳州市| 伊金霍洛旗| 蒙城县| 呼和浩特市| 井冈山市| 通河县| 呼图壁县| 霍邱县| 密云县| 福建省| 莫力| 陆良县| 江都市| 措美县| 扎囊县| 二手房| 峡江县| 阜康市| 宽城| 开鲁县| 星子县| 来凤县| 庄浪县| 盐池县| 礼泉县| 元江| 肥乡县| 吉木乃县| 昌都县| 德安县| 托克托县| 疏勒县| 加查县|