Design patterns are widely used in development. Design patterns refer to the characteristics of our daily life and abstract the characteristics, so that some implementation can meet the specific requirements. Of course, this must be a flexible transformation, and the responsibility chain officially kicked off.
I went to XX Internet company for an interview. The process in a good direction should be that you submitted your resume on the recruitment software, passed the resume screening, HR invitation interview. The interview process is naturally project manager, technical director, boss and HR administration. The big dimension is naturally like this. The conclusion is as follows.
You will have a round of interview. The interview process is similar to a responsibility relationship chain. This process must be installed with specifications. You can't directly talk about salary with Hr, let alone interview with the boss. This is the specific feature.
If you have interviewed the project manager, you have to interview with the technical director. After the technical director has interviewed, you have to talk to the boss. If the boss thinks it appropriate, he will directly ask Hr to contact you. The basic boss will ask you about your expectations.
However, after three rounds of interviews, I pass ed the HR interview. HR asked a question: How did you change 4 or 5 companies after six years of work? In fact, you are still too young. In fact, you can't stand it. You want to say that I jump if you want. I work to make money. But you can't say that. It's clearly about money, but you have to say it with incomparable noble sentiment. The Internet is also too involved
Start the topic:
Responsibility chain design pattern: in simple terms, a set of processes, a set of specifications, specific behaviors and specified implementations are combined into a design pattern.
Based on the above scenario, we conclude:
Public behaviors and methods: interview, interview result feedback, the next round of interview, and overall interview records.
Define abstract hanlder:
package com.xy.design.hanlder; /** * <p> * Extraction of public implementation methods, common behavior, interview * @author xy * @since 2021-10-21 */ public abstract class InterviewHanlder { /** * Define a global Hanlder */ protected InterviewHanlder interviewHanlder; /** * Methods of extracting common behavior, interview */ public abstract void getTheInterview(); /** * Feedback of interview results to the next round of interview * @param nextGatewayHandler */ public void setNextGatewayHandler(InterviewHanlder nextGatewayHandler) { this.interviewHanlder = nextGatewayHandler; } /** * Continue with the next round of interview */ protected void nextInterviewFlag() { if (interviewHanlder != null) interviewHanlder.getTheInterview(); }
Responsibility process realization:
The first level is the realization of project manager interview:
package com.xy.design.hanlder.impl; import com.xy.design.common.Constants; import com.xy.design.hanlder.InterviewHanlder; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; /** * Project manager interview * First level interview */ @Service(Constants.INTERVIEW_PM) @Component public class PMHandler extends InterviewHanlder { @Override public void getTheInterview() { System.out.println("Project manager interview--adopt----------------"); nextInterviewFlag(); } }
The second step is to realize the interview of technical director:
package com.xy.design.hanlder.impl; import com.xy.design.common.Constants; import com.xy.design.hanlder.InterviewHanlder; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; /** * Interview with technical director * Second level interview */ @Service(Constants.INTERVIEW_JS) @Component public class TechnologyHandler extends InterviewHanlder { @Override public void getTheInterview() { System.out.println("Interview with technical director--adopt----------------"); nextInterviewFlag(); } }
Third, the boss interview realizes:
package com.xy.design.hanlder.impl; import com.xy.design.common.Constants; import com.xy.design.hanlder.InterviewHanlder; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; /** * Boss interview * The third level interview */ @Service(Constants.INTERVIEW_BOOS) @Component public class BoosHandler extends InterviewHanlder { @Override public void getTheInterview() { System.out.println("Boss interview--adopt----------------"); nextInterviewFlag(); } }
The fourth pass is hr interview realization
package com.xy.design.hanlder.impl; import com.xy.design.common.Constants; import com.xy.design.hanlder.InterviewHanlder; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; /** * hr interview * The fourth is hr administrative interview */ @Service(Constants.INTERVIEW_HR) @Component public class HrHandler extends InterviewHanlder { @Override public void getTheInterview() { System.out.println("HR Talk about interview--adopt----------------"); } }
Specific implementation classes:
package com.xy.design.service; import com.xy.design.common.Constants; import com.xy.design.hanlder.InterviewHanlder; import com.xy.design.utils.SpringUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * <p> * Specific implementation class of responsibility chain * @author xy * @since 2021-10-21 */ @Service public class interviewHanlderServiceImpl implements InterviewHandlerService { private InterviewHanlder firstGatewayHandler; @Override public InterviewHanlder getHandler() { //todo here is best written as a dynamic database configuration. I test the use of write dead mode here InterviewHanlder firstInterviewHanlder = SpringUtils.getBean(Constants.INTERVIEW_PM, InterviewHanlder.class); //Set the responsibility chain execution in sequence List<String> hanlderList = new ArrayList<>(); hanlderList.add(Constants.INTERVIEW_JS); hanlderList.add(Constants.INTERVIEW_BOOS); hanlderList.add(Constants.INTERVIEW_HR); //Receive the global Hanlder with a temporary variable InterviewHanlder temoInterviewHanlder = firstInterviewHanlder; for (String hanlder : hanlderList) { //Get the implementation class springcontext through proxy InterviewHanlder hanlderImpl = SpringUtils.getBean(hanlder, InterviewHanlder.class); temoInterviewHanlder.setNextGatewayHandler(hanlderImpl); } this.firstGatewayHandler = firstInterviewHanlder; return firstGatewayHandler; } }
Common parameters:
/** * Project manager identification */ public static String INTERVIEW_PM = "pm"; /** * Identification of technical director */ public static String INTERVIEW_JS = "js"; /** * Boss logo */ public static String INTERVIEW_BOOS = "boos"; /** * Hr identification */ public static String INTERVIEW_HR = "hr";
controller:
package com.xy.design.controller; import com.xy.design.hanlder.InterviewHanlder; import com.xy.design.service.InterviewHandlerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HandlerController { @Autowired private InterviewHandlerService interviewHandlerService; @RequestMapping("/interview") public String interview() { InterviewHanlder interviewHanlder = interviewHandlerService.getHandler(); interviewHanlder.getTheInterview(); return "interview pass It fell, Hr Let me give her money to study technology in the company......."; } }
If we succeed, our complete set of responsibility chain will be realized. Level by level, isn't it super simple.