การติดตั้งอินเทอร์เฟซตามที่แสดงให้เห็นอย่างเรียบง่ายและชัดเจนโดย dfa นั้นสะอาดและสวยงาม (และวิธีที่รองรับ "อย่างเป็นทางการ") นี่คือสิ่งที่แนวคิดของอินเทอร์เฟซมีไว้สำหรับ
ใน C # เราสามารถใช้ delegates สำหรับโปรแกรมเมอร์ที่ชอบใช้ functon pointers ใน c แต่เทคนิคของ DFA คือวิธีใช้
คุณสามารถมีอาร์เรย์ได้เช่นกัน
Command[] commands =
{
  new CommandA(), new CommandB(), new CommandC(), ...
}
จากนั้นคุณสามารถรันคำสั่งด้วยดัชนี
commands[7].exec();
การคัดลอกผลงานจาก DFA แต่มีคลาสพื้นฐานที่เป็นนามธรรมแทนที่จะเป็นอินเทอร์เฟซ สังเกต cmdKey ซึ่งจะใช้ในภายหลัง จากประสบการณ์ฉันตระหนักดีว่าบ่อยครั้งที่คำสั่งอุปกรณ์มีคำสั่งย่อยด้วย
abstract public class Command()
{
  abstract public byte exec(String subCmd);
  public String cmdKey;
  public String subCmd;
}
สร้างคำสั่งของคุณดังนั้น
public class CommandA
extends Command
{
  public CommandA(String subCmd)
  {
    this.cmdKey = "A";
    this.subCmd = subCmd;
  }
  public byte exec()
  {
    sendWhatever(...);
    byte status = receiveWhatever(...);
    return status;
  }
}
จากนั้นคุณสามารถขยาย HashMap หรือ HashTable ทั่วไปได้โดยให้ฟังก์ชันการดูดคู่คีย์ - ค่า:
public class CommandHash<String, Command>
extends HashMap<String, Command>
(
  public CommandHash<String, Command>(Command[] commands)
  {
    this.commandSucker(Command[] commands);
  }
  public commandSucker(Command[] commands)
  {
    for(Command cmd : commands)
    {
      this.put(cmd.cmdKey, cmd);
    }
  }
}
จากนั้นสร้างที่เก็บคำสั่งของคุณ:
CommandHash commands =
  new CommandHash(
  {
    new CommandA("asdf"),
    new CommandA("qwerty"),
    new CommandB(null),
    new CommandC("hello dolly"),
    ...
  });
ตอนนี้คุณสามารถส่งการควบคุมอย่างเป็นกลาง
commands.get("A").exec();
commands.get(condition).exec();