{"id":200567,"date":"2020-09-22T09:48:34","date_gmt":"2020-09-22T01:48:34","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=200567"},"modified":"2020-09-11T09:49:59","modified_gmt":"2020-09-11T01:49:59","slug":"interpreter-pattern","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/interpreter-pattern.html","title":{"rendered":"\u8bbe\u8ba1\u6a21\u5f0f\u4e4b\u89e3\u91ca\u5668\u6a21\u5f0f"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u89e3\u91ca\u5668\u6a21\u5f0f\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u8bed\u8a00\uff0c\u5b9a\u4e49\u5b83\u7684\u6587\u6cd5\u7684\u4e00\u79cd\u8868\u793a\uff0c\u5e76\u5b9a\u4e49\u4e00\u4e2a\u89e3\u91ca\u5668\uff0c\u8fd9\u4e2a\u89e3\u91ca\u5668\u4f7f\u7528\u8be5\u8868\u793a\u6765\u89e3\u91ca\u8bed\u8a00\u4e2d\u7684\u53e5\u5b50\u3002\u8fd9\u548c\u89e3\u91ca\u578b\u7f16\u7a0b\u8bed\u8a00\u7684\u89e3\u91ca\u5668\u6709\u70b9\u7c7b\u4f3c\uff0c\u8981\u6839\u636e\u4e00\u6bb5\u8f93\u5165\u8f6c\u6362\u6210\u4e00\u6bb5\u8f93\u51fa\uff0c\u5c06\u4e0d\u6613\u8bfb\u7684\u6587\u672c\u8f6c\u6362\u4e3a\u6613\u8bfb\u7684\u6587\u672c\uff0c\u5c06\u673a\u5668\u4e0d\u80fd\u8bc6\u522b\u7684\u8f93\u5165\u8f6c\u6210\u4e8c\u8fdb\u5236\u673a\u5668\u53ef\u8bfb\u7684\u8f93\u51fa\u3002\u5f53\u6709\u4e00\u4e2a\u8bed\u8a00\u9700\u8981\u89e3\u91ca\u6267\u884c\uff0c\u5e76\u4e14\u4f60\u53ef\u4ee5\u5c06\u8be5\u8bed\u8a00\u4e2d\u7684\u53e5\u5b50\u8868\u793a\u4e3a\u4e00\u4e2a\u62bd\u8c61\u8bed\u6cd5\u6811\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u89e3\u91ca\u5668\u6a21\u5f0f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Prototype<\/strong><\/div>\n Context: \u89e3\u91ca\u5668\u4e0a\u4e0b\u6587 Sample<\/strong><\/div>\n \r\npublic class Context\r\n{\r\n public string Input { get; set; }\r\n public string Output { get; set; }\r\n}\r\n\r\npublic abstract class AbstractExpression\r\n{\r\n public abstract void Interpret(Context context);\r\n}\r\npublic class TerminalExpression : AbstractExpression\r\n{\r\n public override void Interpret(Context context)\r\n {\r\n Console.WriteLine(\"TerminalExpressionInterpreter\");\r\n }\r\n}\r\npublic class NoneTerminalExpression : AbstractExpression\r\n{\r\n public override void Interpret(Context context)\r\n {\r\n Console.WriteLine(\"NonTerminalExpressionInterpreter\");\r\n }\r\n}\r\n\r\n\r\nvar context = new Context();\r\nICollection |