Tag: ocp

理解开放封闭原则

当我遇到以下代码时,我正在重构 一个简单的脚本文件解析器的旧代码: StringReader reader = new StringReader(scriptTextToProcess); StringBuilder scope = new StringBuilder(); string line = reader.ReadLine(); while (line != null) { switch (line[0]) { case ‘$’: // Process the entire “line” as a variable, // ie add it to a collection of KeyValuePair. AddToVariables(line); break; case ‘!’: // Depending of what comes after the ‘!’ […]