Friends who have used macros should know that using macros can 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 Pulse" and "Ice Arrow". The program example is as follows:
package responsibility;/** * DOC skill interface, skills to be bound must implement this interface* */public interface ISkill { public void castSkill();}package responsibility;import java.util.ArrayList;import java.util. List;/** * DOC macro class, used to tie multiple skills together to achieve one-click casting* */public class Macro { /** * DOC collection of multiple skills tied together*/ public List<ISkill > skills = new ArrayList<ISkill>(); /** * * DOC casts skills in the binding order. */ public void castSkill() { for (int i = 0; i < skills.size(); i++) { skills.get( i).castSkill(); } } /** * DOC binding skill. * * @param skill */ public void bindSkill(ISkill skill) { skills.add(skill); }}package responsibility;/** * DOC Ice Arrow skill, no cooling time* */public class IceArrow implements ISkill { @Override public void castSkill() { System.out.println("Cast--"Ice Arrow"); }}package responsibility;/* * * DOC Ice-Blooded Cold Pulse skill, cooling time 2 minutes*/public class IceBloodFast implements ISkill { @Override public void castSkill() { // This can be used to determine whether the skill is cooling down. System.out.println("Cast--"Ice-Blooded Cold Pulse") is omitted here; }}
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 results:
Now casting--"Ice-blooded cold pulse casting--"Ice Arrow
Summary: The chain of responsibility model is mainly used when a request may have multiple objects to process.