shell解释器伪代码问题!

世界没我不行 2018-03-21 09:42:07
)以下程序是一个 Shell解释器的伪代码,请指出以下程序违反了什么设计原
则,并指出如何改正这个程序::
public void Parse()
{
StringReader reader = new StringReader(scriptTextToProcess); StringBuilder scope = new StringBuilder();
string line = reader.ReadLine();
scope = new StringBuilder();
while (line != null)
{
switch (line[0])
{
case '$':
// Process the entire "line" as a variable,
// i.e. add it to a collection of KeyValuePair.
line.AddToVariables(); break;
case '!':
// Depending of what comes after the '!' character,
// process the entire "scope" or command in "line".
if (line == "!execute")
scope.ExecuteScope();
else if (line.StartsWith("!custom_command"))
line.RunCustomCommand(scope);
else if (line == "!single_line_directive")
line.ProcessDirective(); break;
default:
// No processing directive, i.e. add the "line"
// to the current scope. scope.Append(line); break;
}
line = reader.ReadLine();
}
}
求助啊没太看懂QAQ还没学到这里啊,老师就留了作业
...全文
385 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
世界没我不行 2018-03-24
  • 打赏
  • 举报
回复
那改正的话,是要基本大部分的代码都要重新弄么?QAQ我们还没接触过shell解释器啊,程序设计方法的老师就留了这种作业...
byds520 2018-03-21
  • 打赏
  • 举报
回复
这个写的太紧耦合了,读文件是一个功能,根据信息判断作什么操作是一个功能,这个程序把这两个功能写一起了,如果想加新的判断逻辑就需要动核心代码,不好扩展。判断逻辑那里想往再深层次写就用上设计模式...

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧