下面的Compile函数是否违反了the law of demeter, 如果违反了,如何修改?
class Condition{
string field_name;
string opt;
string pattern;
};
class Rule {vector<Condition*> conditions;}
clas RuleSet {vector<Rule*> rules;}
class Matcher{
bool Compile(Rule[] rules)
{
map<string, vector<string> > m; //name+opt => patterns
for(int i=0;i<rules.size();i++)
{
Rule& rule = rules[i];
for(int j=0;j<r.conditions.size();j++)
{
Condition& condition = r.conditions[j];
string name = condition.GetName();
string opt = condition.GetOpt();
string pattern = condition.GetPattern();
iter = m.find(name + opt);
if(found)
{
iter->second.push_back(pattern);
}
else
{
m.insert(name+opt, vector{pattern});//第一个
}
}
}
DoSomeThing(m);
}
※ 修改:·lc900 于 Jul 17 00:12:50 2021 修改本文·[FROM: 111.194.45.*]
※ 来源:·水木社区
http://www.mysmth.net·[FROM: 111.194.45.*]
修改:lc900 FROM 111.194.45.*
FROM 111.194.45.*