[英]What is the thing I'm trying to do called?
I think there must be a name for whatever it is I'm trying to do. 我认为无论我想做什么,都必须有个名字。 I want to have a list of... requests and what the responses should look like.
我要列出...请求以及响应的外观。 But the different requests and responses are not formatted the same.
但是不同的请求和响应的格式不同。 They are simple strings, so here's some examples:
它们是简单的字符串,因此这里有一些示例:
request => response
foo%% => "OK"
foo? => "%%"
%%%%bar => "OK"
Version? => "Baz-%%%%"
Where % could be a number or letter. 其中%可以是数字或字母。
I can code for each possible command with a big switch/case, but I wanted to make it more extend-able and maybe testable. 我可以使用较大的开关/案例为每个可能的命令编写代码,但我想使其更具扩展性,甚至可以进行测试。 Sorry this question is so vague.
抱歉,这个问题太含糊了。 Please rename it and/or tag it correctly.
请重命名和/或正确标记。
I'm doing this in javascript/node if it matters. 如果有问题,我正在javascript / node中执行此操作。
我不知道您要发明什么,但这听起来像是正则表达式。
在这种情况下,您将%
称为通配符。
Your code will need parse the input to verify syntactic correctness and output a data structure that represents the input. 您的代码将需要解析输入以验证语法的正确性,并输出代表输入的数据结构。 Then you will need to analyze your intermediate data structure to determine semantics.
然后,您将需要分析中间数据结构以确定语义。 The simplest way would be to use objects that implement a common interface.
最简单的方法是使用实现公共接口的对象。
object FooRequest (value)
implements Request
method Process ()
return "OK"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.