In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "template code sharing of Java programming responsibility chain mode". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
/ / Abstract handler public abstract class Handler {private Handler nextHandler; / / each processor must process the request public final Response handleMessage (Request request) {Response response = null; / / to determine whether its own processing level if (this.getHandlerLevel (). Equals (request.getRequestLevel () {response = this.echo (request) } else {/ / determine whether there is a next processor if (this.nextHandler! = null) {response = this.nextHandler.handleMessage (request);} else {/ / does not have a proper handler}} return response;} / / set who the next processor is public void setNext (Handler _ handler) {this.nextHandler = _ handler } / / each processor has a processing level protected abstract Level getHandlerLevel (); / / each processor must implement the processing task protected abstract Response echo (Request request);} / / specific processors 1 publlic class ConcreteHandler1 extends Handler {/ / define their own processing logic protected Response echo (Request request) {/ / complete processing logic return null } / / set your own processing level protected Level getHandlerLevel () {/ / set your own processing level return null;} / / specific processors 2 publlic class ConcreteHandler2 extends Handler {/ / define your own processing logic protected Response echo (Request request) {/ / complete processing logic return null } / / set your own processing level protected Level getHandlerLevel () {/ / set your own processing level return null;} / / specific processors 3 publlic class ConcreteHandler3 extends Handler {/ / define your own processing logic protected Response echo (Request request) {/ / complete processing logic return null } / / set your own processing level protected Level getHandlerLevel () {/ / set your own processing level return null;} / / the code about the framework in the mode public class Level {/ / define a request and processing level} public class Request {/ / request level public Level getRequestLevel () {return null } public class Response {/ / process the data of the returnee} / / scene class public class Client {public static void main (String [] args) {/ / declare all processing nodes Handler handler1 = new ConcreteHandler1 (); Handler handler2 = new ConcreteHandler2 (); Handler handler2 = new ConcreteHandler3 (); / / set the phase order in the chain 1-> 2-handler1.setNext-> 3 handler1.setNext (handler2); handler2.setNext (handler3) / / submit request Response response = handler.handleMessage (new Request ());}} "template code sharing of Java programming responsibility chain mode" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 238
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.