For those who have used macros, you should know that you can use macros to bind multiple skills to one key. For example, if the skill ranked first has a CD, this skill will be skipped and the subsequent skills will be executed. I remember when I used to play DK, when fighting monsters, I just used one button and just kept pressing it. In the doGet and doPost methods in the servlet, we usually send the doGet request to doPost for processing. This is also a chain of responsibility model.
Here, there is a macro that binds the two skills "Ice-Blooded Cold Vein" and "Ice Arrow". The program example is as follows:
package responsibility; /** * DOC 技能接口,要绑定的技能都要实现这个接口 * */ public interface ISkill { public void castSkill(); } package responsibility; import java.util.ArrayList; import java.util.List; /** * DOC 宏类,用来把多个技能绑在一起,实现一键施放 * */ public class Macro { /** * DOC 多个技能绑在一起的集合 */ public List<ISkill> skills = new ArrayList<ISkill>(); /** * * DOC 按照绑定顺序施放技能. */ public void castSkill() { for (int i = 0; i < skills.size(); i++) { skills.get(i).castSkill(); } } /** * DOC 绑定技能. * * @param skill */ public void bindSkill(ISkill skill) { skills.add(skill); } } package responsibility; /** * DOC 寒冰箭技能,无冷却时间 * */ public class IceArrow implements ISkill { @Override public void castSkill() { System.out.println("施放--》寒冰箭"); } } package responsibility; /** * DOC 冰血冷脉技能,冷却时间2分钟 */ public class IceBloodFast implements ISkill { @Override public void castSkill() { // 这里可以用来判断技能是否在冷却当中,这里略去了 System.out.println("施放--》冰血冷脉"); } }
Test class:
package responsibility; public class Main { public static void main(String[] args) { Macro macro = new Macro(); macro.bindSkill(new IceBloodFast()); macro.bindSkill(new IceArrow()); macro.castSkill(); } }
Test result:
正在施放--》冰血冷脉 施放--》寒冰箭
Summary: The chain of responsibility model is mainly used for situations where a request may have multiple objects to be processed.
For more articles related to the introduction of the chain of responsibility model of Java design patterns, please pay attention to the PHP Chinese website!
Related articles:
Detailed introduction to the code for implementing the Mediator pattern in Java

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software