In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
The article begins with:
Behavioral model: responsibility chain model
The fourth of the eleven behavioral models: the responsibility chain model.
Brief introduction
Name: chain of responsibility model
English name: Chain of Responsibility Pattern
Values: the responsibility belongs to me
Personal introduction:
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.Chain the receiving objects and pass the request along the chain until an object handles it.
Multiple objects have the opportunity to process the request, thus avoiding the coupling relationship between the sender and receiver of the request. Join these objects into a chain and pass the request along the chain until an object processes it.
(from the Zen of Design patterns)
The story you want.
It is almost time for gold, silver and silver, and many students are eager to go outside to see the world, but do you know the interview process of the major enterprises in advance? Here I will give you popular science about the interview process of most Internet companies, which happens to be useful in the chain of responsibility model.
In Internet companies, the recruitment process for the position of programmer is more or less the same, and generally there will be at least three rounds of interviews, which are two rounds of technical interview and one round of HR. And these rounds of interviews are progressive, the first interview is generally the group leader interview, after passing is the department leader interview, and then through the HR interview, after the HR interview, you can successfully get the Offer.
The story begins when Xiaoming participates in an interview with a company, and the recruitment process of a company is the three rounds of interviews mentioned above. The interviewers of the recruitment process are: the first side is the team leader Lao Gang, the second side is the department manager Lao Sun, and the third side is the final face of HR Lao Liu. Why is this scene in line with the chain of responsibility model? First of all, no matter the team leader, the department manager or the HR, they all act as interviewers, and the interviewer gives them the right to interview the students who come to the company for an interview, and the result of the interview is transferable, that is, if the interview passes, it will go to the next round of interview and eventually become a delivery chain. We use code to simulate this process.
Public class ChainOfResponsibilityTest {public static void main (String [] args) {Interviewee interviewee = new Interviewee ("Xiaoming"); TeamLeader teamLeader = new TeamLeader ("Lao Gang"); DepartMentManager departMentManager = new DepartMentManager ("Lao Sun"); HR hr = new HR ("Lao Liu"); / / set the interview process teamLeader.setNextInterviewer (departMentManager); departMentManager.setNextInterviewer (hr) / / start interview teamLeader.handleInterview (interviewee);}} / * * interviewer * / class Interviewee {private String name; private boolean teamLeaderOpinion; private boolean departMentManagerOpinion; private boolean hrOpinion; public Interviewee (String name) {this.name = name;} public String getName () {return name;} public void setName (String name) {this.name = name } public boolean isTeamLeaderOpinion () {return teamLeaderOpinion;} public void setTeamLeaderOpinion (boolean teamLeaderOpinion) {this.teamLeaderOpinion = teamLeaderOpinion;} public boolean isDepartMentManagerOpinion () {return departMentManagerOpinion;} public void setDepartMentManagerOpinion (boolean departMentManagerOpinion) {this.departMentManagerOpinion = departMentManagerOpinion;} public boolean isHrOpinion () {return hrOpinion;} public void setHrOpinion (boolean hrOpinion) {this.hrOpinion = hrOpinion Interviewer * / abstract class Interviewer {protected String name; protected Interviewer nextInterviewer; public Interviewer (String name) {this.name = name;} public Interviewer setNextInterviewer (Interviewer nextInterviewer) {this.nextInterviewer = nextInterviewer; return this.nextInterviewer;} public abstract void handleInterview (Interviewee interviewee) } / * team leader * / class TeamLeader extends Interviewer {public TeamLeader (String name) {super (name);} @ Override public void handleInterview (Interviewee interviewee) {System.out.println ("team leader [" + this.name + "] interview [" + interviewee.getName () + "] classmate"); interviewee.setTeamLeaderOpinion (new Random (). NextBoolean ()) If (interviewee.isTeamLeaderOpinion ()) {System.out.println ("[" + interviewee.getName () + "] passed the round interview of the group leader"); this.nextInterviewer.handleInterview (interviewee);} else {System.out.println ("[" + interviewee.getName () + "] failed the round interview of the group leader") } / * Department Manager * / class DepartMentManager extends Interviewer {public DepartMentManager (String name) {super (name);} @ Override public void handleInterview (Interviewee interviewee) {System.out.println ("Department Manager [" + this.name + "] interview [" + interviewee.getName () + "] classmate"); interviewee.setDepartMentManagerOpinion (new Random (). NextBoolean ()) If (interviewee.isDepartMentManagerOpinion ()) {System.out.println ("[" + interviewee.getName () + "] classmate department manager passed the round interview"); this.nextInterviewer.handleInterview (interviewee);} else {System.out.println ("[" + interviewee.getName () + "] classmate department manager failed the round interview") } / * HR * / class HR extends Interviewer {public HR (String name) {super (name);} @ Override public void handleInterview (Interviewee interviewee) {System.out.println ("HR [" + this.name + "] interview [" + interviewee.getName () + "] classmate"); interviewee.setHrOpinion (new Random (). NextBoolean ()) If (interviewee.isHrOpinion ()) {System.out.println ("[" + interviewee.getName () + "] classmate HR round interview, congratulations on getting Offer");} else {System.out.println ("[" + interviewee.getName () + "] classmate HR round interview failed") Print result: team leader [Lao Gang] interviewed [Xiaoming] classmate [Xiaoming] classmate group leader round interview through department manager [Lao Sun] classmate [Xiaoming] classmate [Xiaoming] classmate department manager round interview passed HR [Lao Liu] interviewed [Xiaoming] classmate [Xiaoming] classmate HR round interview, congratulations on getting the Offer
The printed result of the above code is that Xiao Ming passed the interview and got the Offer through layers of screening. The following picture shows the process of this interview.
Explain the code, Interviewee is the interviewer, for the enterprise, this interviewer comes to the interview process will have three key marks, that is, the evaluation of the interviewer by three interviewers, only a good evaluation can get the Offer through the interview, so the Interviewee category has the interview results of three interviewers. Interviewer is an interview official, the interviewer in the enterprise is not a position, but a job, to help the enterprise recruit the right talent, so it is an abstract class, there is an abstract way is to interview candidates, the specific interview process and the interviewer to achieve, and because this interview will have feedback, good results will enter the next round of interviews, so there will be the next interviewer's object reference The model of chain of responsibility is also reflected here. TeamLeader, DepartMentManager and HR are different positions in the company, and these positions all need to act as interviewers when the company needs to recruit, so they all inherit Interviewer. This whole process constitutes an example of the chain of responsibility pattern code. I hope that all the eager friends in the gold, silver and silver can break through to the last level and win the HR sister.
Code:
Chain of Responsibility Pattern
Summary
The chain of responsibility model encapsulates the processing logic very well. In the code, we only see the interview of the team leader, but the interview of the department manager and HR is actually hidden behind it. Does the chain of responsibility look familiar? Have you ever been useful when developing Java Web projects? The Filter filter is implemented in the chain of responsibility mode. The above code also uses another pattern, which is not clearly pointed out to test the effect of learning these design patterns. Students who know it can leave a message.
Recommended reading:
Creative mode: singleton mode (Xiaoming has only one car)
Creative model: factory method (Xiaoming's garage)
Creative model: abstract factory (BMW cars have to use BMW tires and BMW steering wheels)
Creative model: builder mode (soup is so hot)
Creative model: prototype model (photocopying books)
Behavioral model: template method (sneaker manufacturing process)
Behavioral model: intermediary model (renting a house to find an intermediary)
Behavioral mode: command mode (technical manager assigns tasks)
The official account replied "Gift package" to get tutorials such as Java, Python, IOS, etc.
Add personal Wechat comments "tutorials" to get tutorials for architects, machine learning, etc.
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: 0
*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.