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

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.

主站蜘蛛池模板: 平罗县| 台前县| 临江市| 溆浦县| 习水县| 邵阳市| 晋州市| 舒兰市| 金华市| 台湾省| 贵溪市| 海盐县| 临清市| 乐山市| 广安市| 渝中区| 林周县| 九寨沟县| 乌鲁木齐县| 邻水| 唐河县| 无为县| 泗洪县| 黔东| 安龙县| 青田县| 澄城县| 沂南县| 浙江省| 象州县| 宝坻区| 翁源县| 绥德县| 辽中县| 河津市| 同心县| 新野县| 新竹市| 丰镇市| 孟州市| 营山县|