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

The chain-of-responsibility pattern

Computer software is for processing information, and there are different ways of structuring and processing that information. We already know that when we talk about object-oriented programming, we should assign a single responsibility to each class in order to make our design easy to extend and maintain.

Consider a scenario where multiple types of operations can be performed on a set of data that comes with a client request. Instead of adding information about all the operations in a single class, we can maintain different classes responsible for the different types of operations. This helps us keep our code loosely coupled and clean.

These classes are called handlers. The first handler will receive the request and take a call if it needs to perform an action, or pass it on to the second handler. Similarly, the second handler checks and can pass on the request to the next handler in the chain.

主站蜘蛛池模板: 锡林浩特市| 九寨沟县| 桂林市| 普宁市| 桂阳县| 百色市| 浦北县| 邵阳县| 上高县| 大洼县| 和政县| 伊宁县| 宣威市| 平原县| 尚志市| 台湾省| 独山县| 卫辉市| 青龙| 吉安市| 桐乡市| 临漳县| 潜山县| 南郑县| 望都县| 育儿| 宁德市| 凤阳县| 武陟县| 寻甸| 鱼台县| 阿拉尔市| 金堂县| 开江县| 奈曼旗| 潢川县| 遂昌县| 姜堰市| 上犹县| 文水县| 沙雅县|