0
私は機能管理サブシステムの依存関係を解決する関数を書いています。私が思いついた擬似コードを見て、私が何かを逃したかどうかを知らせてください(おそらく私が持っている)。擬似コードレビュー - 機能依存性チェック
var featuresUnderAnalysis = new List<Feature>();
bool DependenciesAreMet(Feature feature)
{
if(featuresUnderAnalysis.Contains(feature)) //see note 1
{
throw new CircularDependencyDetectedException();
}
featuresUnderAnalysis.Add(feature);
if feature has no dependencies then
{
featuresUnderAnalysis.Remove(feature);
return true;
}
else
{
foreach dependency feature has
{
if(!DependenciesAreMet(dependency)) return false;
}
featuresUnderAnalysis.Remove(feature);
return true;
}
}
//note1: we maintain a list of features we have met and not
//yet resolved the dependencies for. If we come across
//a feature and find it in the featuresUnderAnalysis
//list then we realise that resolution of a feature's
//dependency graph depends on resolution of it's graph
//and hence we cannot complete, and we throw an exception.