The Chain of Responsibility Pattern creates a chain of recipient objects for a request. This pattern gives the type of request and decouples the sender and receiver of the request. This type of design pattern is a behavioral pattern. In this pattern, typically each receiver contains a reference to another receiver. If an object cannot […]
Tag: responsibility
How to use the chain of responsibility pattern elegantly in business code
By using the chain of responsibility model, we can handle requests more flexibly and gracefully, reduce the coupling between codes, and improve the maintainability and scalability of the code. In some scenarios with complex business logic or where requests need to be processed dynamically, using the chain of responsibility pattern will be a good choice. […]
21 Behavioral model-Chain of responsibility model
1 Introduction to chain of responsibility model 2 Principle of chain of responsibility model 3 Implementation of chain of responsibility model The implementation of the chain of responsibility pattern is very simple. Each specific processing class will be saved in the next processing class after it. When the processing is completed, the next set processing […]
Decoration mode (Democrator) – single responsibility class, structural mode
In some cases, we may “excessively use inheritance to extend the functionality of objects”. Due to the static characteristics introduced by inheritance for types, this extension method lacks flexibility; and with the increase of subclasses (the increase of extension functions) ), the combination of various subclasses (combination of extended functions) will lead to the expansion […]
Bridge pattern (Bridge) – single responsibility class, structural model
Due to the inherent implementation logic of certain types, they have two dimensions of change, or even changes in multiple dimensions. How to deal with this “multi-dimensional change”? How to use object-oriented technology to make types easily change in two or even multiple directions without introducing additional complexity. In fact, I was stunned when I […]
Mybatis mapper and XML configuration responsibility separation
Previously we introduced the use of XML configuration method to complete the operations of adding, deleting, modifying and querying data. When using this method, you need to use [namespace.tag number] when actually calling. This method is very convenient when writing SQL statements, but when executing The SQL statement link is not very elegant; in addition, […]
Reading OkHttp source code in Android 2 (chain of responsibility model)
The blogger discovered a giant artificial intelligence learning website a few days ago. It is easy to understand and humorous. I can’t help but share it with everyone. Click to jump to the tutorial Android OkHttp source code reading detailed explanation 1 Looking at the OkHttp source code, I found that OkHttp uses the responsibility […]
How to use the chain of responsibility pattern elegantly in business code
The Chain of Responsibility Pattern creates a chain of recipient objects for a request. This pattern gives the type of request and decouples the sender and receiver of the request. This type of design pattern is a behavioral pattern. In this pattern, typically each receiver contains a reference to another receiver. If an object cannot […]
Improve code readability and maintainability: Use the chain of responsibility model to optimize your Spring Boot code
1. Basic introduction Chain of responsibility is a very common design pattern. I won’t introduce it in detail. This article explains how to use the chain of responsibility pattern elegantly in SpringBoot. 1.1. Code execution process The basic steps are as follows: When SpringBoot starts, you need to obtain the corresponding Bean of the handler. […]
Code simplification 10 times, responsibility chain model yyds
Thisisacommunitythatmaybeusefultoyou One-to-onecommunication/interviewbrochure/resumeoptimization/jobsearchquestions,welcometojointhe”YudaoRapidDevelopmentPlatform“KnowledgePlanet.ThefollowingissomeinformationprovidedbyPlanet: “ProjectPractice(Video)”:Learnfrombooks,“practice”frompastevents “InternetHighFrequencyInterviewQuestions”:Studyingwithyourresume,springblossoms “ArchitecturexSystemDesign”:Overcomingdifficultiesandmasteringhigh-frequencyinterviewscenarioquestions “AdvancingJavaLearningGuide”:systematiclearning,themainstreamtechnologystackoftheInternet “Must-readJavaSourceCodeColumn”:Knowwhatitisandwhyitisso Thisisanopensourceprojectthatmaybeusefultoyou DomesticStarisa100,000+opensourceproject.Thefront-endincludesmanagementbackend+WeChatapplet,andtheback-endsupportsmonomerandmicroservicearchitecture. FunctionscoverRBACpermissions,SaaSmulti-tenancy,datapermissions,mall,payment,workflow,large-screenreports,WeChatpublicaccount,etc.: Bootaddress:https://gitee.com/zhijiantianya/ruoyi-vue-pro Cloudaddress:https://gitee.com/zhijiantianya/yudao-cloud Videotutorial:https://doc.iocoder.cn Source:Internet Whatischainofresponsibility scenestobeused Counterexample preliminaryrenovation shortcoming Responsibilitychaintransformation Responsibilitychainfactorytransformation Conclusion Recently,Ihadamemberofmyteamwriteanimportfunction.Heusedthechainofresponsibilitymodel,whichresultedinalotofcodeandmanybugs.ItdidnotachievetheresultsIexpected. Infact,fortheimportfunction,Ithinkthetemplatemethodismoresuitable!Tothisend,theteamnextdooralsotookoutourcaseandconductedacollectivecodereview. Learndesignpatternswell,anddon’tforcethemtousethemjustforpractice!Afunctionthatcouldhavebeenimplementedin100linesnowtook3,000linestowrite!Regardlessofwhetheritisrightorwrong,let’stakealookatthechainofresponsibilitydesignpatternfirst! Whatisthechainofresponsibility TheChainofResponsibilitypatternisabehavioraldesignpatternthatallowsyoutosendrequestsalongachainofhandlers.Afterreceivingarequest,eachhandlercanprocesstherequestorpassitontothenexthandlerinthechain. Backendmanagementsystem+userappletimplementedbasedonSpringBoot+MyBatisPlus+Vue&Element,supportingRBACdynamicpermissions,multi-tenancy,datapermissions,workflow,three-partylogin,payment,SMS,mallandotherfunctions Projectaddress:https://github.com/YunaiV/ruoyi-vue-pro Videotutorial:https://doc.iocoder.cn/video/ Usagescenarios Therearestillmanyusagescenariosforchainofresponsibility: Multi-conditionprocessjudgment:permissioncontrol ERPsystemprocessapproval:generalmanager,personnelmanager,projectmanager TheunderlyingimplementationofJavafilterFilter Ifthisdesignpatternisnotused,thecodewillbebloatedordifficulttomaintainwhentherequirementschange,suchasthefollowingexample. Counterexample Supposethereisalevel-breakinggame.Theconditionforenteringthenextlevelisthatthescoreofthepreviouslevelishigherthanxx: Thegamehas3levelsintotal Enteringthesecondlevelrequiresagamescoreofgreaterthanorequalto80inthefirstlevel. Enteringthethirdlevelrequiresagamescoreof90ormoreinthesecondlevel. Thenthecodecanbewrittenlikethis: //Firstlevel publicclassFirstPassHandler{ publicinthandler(){ System.out.println(“FirstPass–>FirstPassHandler”); return80; } } //Secondlevel publicclassSecondPassHandler{ publicinthandler(){ System.out.println(“SecondPass–>SecondPassHandler”); return90; } […]