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.