×

Loading...

你跟贴太快,我当时正在想办法把代码整齐地显示出来。下面整出来了,希望能使我的观点更直观。

// original code, from the web, probably in C#
private void ProcessLine(string line, IList result) {
   if (isBlank(line)) return;
   if (isComment(line)) return;
   string typeCode = GetTypeCode(line);
   IReaderStrategy strategy = (IReaderStrategy)_strategies[typeCode];
   if (null == strategy)
      throw new Exception("Unable to find strategy");
   result.Add(strategy.Process(line));
} 

// With CommentStrategy and NullStrategy.
private void ProcessLine(string line, IList result) {
    string typeCode = GetTypeCode(line);
    IReaderStrategy strategy = (IReaderStrategy)_strategies[typeCode];
    result.Add(strategy.Process(line));
} 

// Can be safely simplied to:
private void ProcessLine(string line, IList result) {
   result.Add( _strategies[GetTypeCode(line)].Process(line) );
} 

Sign in and Reply Report

Replies, comments and Discussions: