当前位置:网站首页>Responsibility chain mode -- through interview
Responsibility chain mode -- through interview
2022-06-24 20:35:00 【zhanyd】
List of articles
Introduction
Xiaoshuai company HR Interview process for technicians of Xiaoshuai design company . The interview designed at the beginning is divided into three rounds , The first round is a technical interview , The second round is a written test , The third round is the boss interview .
More and more people come to interview later , The staff of the company are nervous , The technical interview can't be arranged , Xiaoshuai is with HR Discuss , Add another round of telephone interview before the technical interview , Make a preliminary screening .HR Let Xiaoshuai keep full flexibility when designing the interview process , You can add... At any time , Delete the interview node , such as , In the future, it may be necessary to add ideological and moral interview links , Cancel the interview with the boss .
Xiaoshuai thinks carefully , This is the responsibility chain model ?
The chain of responsibility model
The chain of responsibility model : Allows you to send requests along the handler chain . Upon receipt of the request , Each handler can process the request , Or pass it on to the next handler on the chain . The responsibility chain pattern is a behavior design pattern .
Xiaoshuai put the function of interview , It is written down with the responsibility chain model .
Event handling class :
/** * Event handling class */
public abstract class Handler {
/** * Next handler */
protected Handler nextHandler = null;
/** * Set up a handler * @param nextHandler * @return */
public Handler setNextHandler(Handler nextHandler) {
this.nextHandler = nextHandler;
return nextHandler;
}
/** * Treatment method * @param abilityValue The ability value of the interviewer */
public abstract void handle(int abilityValue);
}
Telephone interview :
/** * Telephone interview */
public class TelephoneInterviewHandler extends Handler{
/** * Qualified capacity value */
final static int PASS_ABILITY_VALUE = 60;
/** * Treatment method */
@Override
public void handle(int abilityValue) {
if(abilityValue > PASS_ABILITY_VALUE) {
System.out.println(" The telephone interview passed .");
if(nextHandler != null) {
nextHandler.handle(abilityValue);
} else {
System.out.println(" Successful entry !");
}
} else {
System.out.println(" Telephone interview failed .");
}
}
}
Face to face interview :
/** * Face to face interview */
public class FaceInterviewHandler extends Handler{
/** * Qualified capacity value */
final static int PASS_ABILITY_VALUE = 70;
/** * Treatment method * * @param abilityValue Ability value */
@Override
public void handle(int abilityValue) {
if(abilityValue > PASS_ABILITY_VALUE) {
System.out.println(" Pass the face-to-face interview .");
if(nextHandler != null) {
nextHandler.handle(abilityValue);
} else {
System.out.println(" Successful entry !");
}
} else {
System.out.println(" Face to face interview failed .");
}
}
}
Written examination :
/** * written examination */
public class WrittenTestHandler extends Handler{
/** * Qualified capacity value */
final static int PASS_ABILITY_VALUE = 80;
/** * Treatment method * * @param abilityValue Ability value */
@Override
public void handle(int abilityValue) {
if(abilityValue > PASS_ABILITY_VALUE) {
System.out.println(" Pass the written examination .");
if(nextHandler != null) {
nextHandler.handle(abilityValue);
} else {
System.out.println(" Successful entry !");
}
} else {
System.out.println(" The written examination failed .");
}
}
}
Boss interview :
/** * Boss interview */
public class BossInterviewHandler extends Handler{
/** * Qualified capacity value */
final static int PASS_ABILITY_VALUE = 90;
/** * Treatment method * * @param abilityValue Ability value */
@Override
public void handle(int abilityValue) {
if(abilityValue > PASS_ABILITY_VALUE) {
System.out.println(" The boss passed the interview .");
System.out.println(" Successful entry !");
} else {
System.out.println(" The boss failed in the interview .");
}
}
}
Client class :
/** * Client class */
public class Client {
public static void main(String[] args) {
Handler telephoneInterviewHandler = new TelephoneInterviewHandler();
telephoneInterviewHandler.setNextHandler(new FaceInterviewHandler())
.setNextHandler(new WrittenTestHandler())
.setNextHandler(new BossInterviewHandler());
telephoneInterviewHandler.handle(91);
}
}
Output :
The telephone interview passed .
Pass the face-to-face interview .
Pass the written examination .
The boss passed the interview .
Successful entry !
If you don't need a boss interview , Just get rid of the interview with the boss :
/** * Client class */
public class Client {
public static void main(String[] args) {
Handler telephoneInterviewHandler = new TelephoneInterviewHandler();
telephoneInterviewHandler.setNextHandler(new FaceInterviewHandler())
.setNextHandler(new WrittenTestHandler());
telephoneInterviewHandler.handle(85);
}
}
Output :
The telephone interview passed .
Pass the face-to-face interview .
Pass the written examination .
Successful entry !
summary
When a program needs to process a request in a different way , And the treatment is uncertain , When dynamic adjustment is possible , It is suitable to use the responsibility chain model . This mode can connect multiple processors into a chain , All requests go through the handlers on the chain in strict order , And you can dynamically adjust the handler , newly added , Delete or adjust their order .
advantage
- It can flexibly control the order of request processing and the object of processing .
- Comply with the single responsibility principle , Decouple the client and handler classes .
- Comply with opening and closing principle , You can easily add new processors .
shortcoming
- Some requests may not be processed .
- Increase the complexity of the code , There may be many handler classes .
边栏推荐
- Showcase是什么?Showcase需要注意什么?
- 在Dialog中使用透明的【X】叉叉按钮图片
- 情绪识别AI竟「心怀鬼胎」,微软决定封杀它!
- 海泰前沿技术|隐私计算技术在医疗数据保护中的应用
- 16个优秀业务流程管理工具
- DX12引擎开发课程进度-这个课程到底讲到哪里了
- Map跟object 的区别
- 1、 Downloading and installing appium
- VMware virtual machine setting static IP
- "Ningwang" was sold and bought at the same time, and Hillhouse capital has cashed in billions by "selling high and absorbing low"
猜你喜欢
Leetcode (135) - distribute candy
JMeter environment deployment
顺序表的基本操作
字节、腾讯也下场,这门「月赚3000万」的生意有多香?
Cooking business experience of young people: bloggers are busy selling classes and bringing goods, and the organization earns millions a month
When querying the database with Gorm, reflect: reflect flag. mustBeAssignable using unaddressable value
Basic properties and ergodicity of binary tree
Design of routing service for multi Activity Architecture Design
Sequential stack traversal binary tree
Image panr
随机推荐
gateway
Fundamentals of performance testing -- definitions of common terms
天天鉴宝暴雷背后:拖欠数千万、APP停摆,创始人预谋跑路?
The largest DPU manufacturer in history (Part 1)
微信小程序自定义tabBar
Set up your own website (14)
京东一面:Redis 如何实现库存扣减操作?如何防止商品被超卖?
The four stages of cloud computing development have finally been clarified
伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
VXLAN 与 MPLS:从数据中心到城域以太网
云计算发展的 4 个阶段,终于有人讲明白了
VMware virtual machine setting static IP
海泰前沿技术|隐私计算技术在医疗数据保护中的应用
JVM tuning
Basic properties and ergodicity of binary tree
对“宁王”边卖边买,高瓴资本“高抛低吸”已套现数十亿
Unit actual combat lol skill release range
Coinbase将推出首个针对个人投资者的加密衍生产品
[performance tuning basics] performance tuning standards