我对这个序列图有一些怀疑,我在网上没有找到类似的例子,所以我不能比较我的解决方案.
本练习需要使用序列图对Directory
类的listAllFiles
方法的调用进行建模.
这是Java代码:
public class Directory {
public List<File> listAllFiles(String path) {
List<File> all = newArrayList<File>();
File[] list = new File(path).listFiles();
if(list != null) {
for (File f:list) {
if(f.isDirectory()) {
all.addAll(listAllFiles(f.getAbsolutePath()));
} else {
all.add(f.getAbsoluteFile());
}
}
}
return all;
}
}
这是我的序列图:
我按照回复中的建议修改了我的解决方案: