命令 Handler/Parser 用于铁路模拟
Command Handler/Parser for a railway simulation
I am trying to find a good way to create a user interface for my railway simulation.
For now, I have created a "Command" interface with the methods execute, getName, getArguments and then I created a class for each command (AddTrack, DeleteTrack, ..., Exit).
However, I am still struggling with a good way to get all arguments, handling wrong inputs etc. Does someone have a better idea for my UI or can give me some basic structure for it?
Here is the list of all commands that I want to implement:
- add track <startpoint> -> <endpoint>
- delete track <trackID>
- list tracks
- set switch <trackID> position <point>
- create engine <engineType> <class> <name> <length> <couplingFront> <couplingBack>
- list engines
- create coach <coachType> <length> <couplingFront> <couplingBack>
- list coaches
- create train-set <class> <name> <length> <couplingFront> <couplingBack>
- list train-sets
- delete rolling stock <id>
- add train <trainID> <rollingStockID>
- list trains
- show train <trainID>
- put train <trainID> at <point> in direction <x>,<y>
- step <speed>
- exit
将它们全部放在同一个方法中可能是一种不好的做法。这就是为什么我的计划是为每个命令创建一个新的 class。
我的问题是我不确定如何识别这些命令,因为有些命令由一个词组成(如退出、步骤),有些则由两个词组成(添加曲目、删除曲目、设置开关)。您是否建议为所有添加命令(添加轨道、添加列车等)、列表命令(列出轨道、列表引擎等)等创建一个 class?
如果您只想创建一个命令行工具,我会创建一些与 'menu'(命令处理)相关的特定 class,然后为特定的 classes特定领域(与火车、轨道、引擎等相关的事物)。
所以你最终可能会有一些臃肿的命令处理来保存一些状态(比如我们在 cli-app 中的位置),让用户 select 某种状态(如果他想操纵轨道、火车或查看有关引擎的信息)。所有这些东西都在一个(或几个)菜单 classes 中处理。这个 class 负责保存状态和 'navigate' 用户(这意味着调用其他 classes 和方法)。
I am trying to find a good way to create a user interface for my railway simulation.
For now, I have created a "Command" interface with the methods execute, getName, getArguments and then I created a class for each command (AddTrack, DeleteTrack, ..., Exit). However, I am still struggling with a good way to get all arguments, handling wrong inputs etc. Does someone have a better idea for my UI or can give me some basic structure for it?
Here is the list of all commands that I want to implement:
- add track <startpoint> -> <endpoint>
- delete track <trackID>
- list tracks
- set switch <trackID> position <point>
- create engine <engineType> <class> <name> <length> <couplingFront> <couplingBack>
- list engines
- create coach <coachType> <length> <couplingFront> <couplingBack>
- list coaches
- create train-set <class> <name> <length> <couplingFront> <couplingBack>
- list train-sets
- delete rolling stock <id>
- add train <trainID> <rollingStockID>
- list trains
- show train <trainID>
- put train <trainID> at <point> in direction <x>,<y>
- step <speed>
- exit
将它们全部放在同一个方法中可能是一种不好的做法。这就是为什么我的计划是为每个命令创建一个新的 class。
我的问题是我不确定如何识别这些命令,因为有些命令由一个词组成(如退出、步骤),有些则由两个词组成(添加曲目、删除曲目、设置开关)。您是否建议为所有添加命令(添加轨道、添加列车等)、列表命令(列出轨道、列表引擎等)等创建一个 class?
如果您只想创建一个命令行工具,我会创建一些与 'menu'(命令处理)相关的特定 class,然后为特定的 classes特定领域(与火车、轨道、引擎等相关的事物)。
所以你最终可能会有一些臃肿的命令处理来保存一些状态(比如我们在 cli-app 中的位置),让用户 select 某种状态(如果他想操纵轨道、火车或查看有关引擎的信息)。所有这些东西都在一个(或几个)菜单 classes 中处理。这个 class 负责保存状态和 'navigate' 用户(这意味着调用其他 classes 和方法)。