全,
最近,在一次技术面试中,我被要求为文件系统写一个高级设计。我对这个问题的回答如下。我想请大家回顾一下,如果有建议/改进,请让我知道:
interface BaseFileSystem
{
/*Basic file/folder attributes are:
1. File/Folder Size
2. File/Folder Date created
3. File/Folder Date Modified
4. File/Folder permissions - Read, write and execute
5. File/Folder Owner - Owner of the file who defines permissions for other users
6. File/Folder Visibility - Hidden or Visible
7. File/Folder Name
Hence each one of the above attributes would have public <return type> get() and public void set<AttributeName>(<variable datatype>) */
}
public class File implements BaseFileSystem
{
/*The `File` class should implement all of the methods from interface `BaseFilesystem`.
In addition, it must also implement following specific methods that can only be associated with physical files*/
public String getFileExtension(){….}
public void setFileExtension(String value) {….}
public String[] getAssociatedPrograms(){ …..}
public void executable(){ …. };
}
public class Folder implements BaseFileSystem
{
/*The `Folder` class should implement all of the methods from interface `BaseFileSystem`. In addition, it must also implement following specific methods that can only be associated with the physical 'folders'*/
public BaseFileSystem[] getSubFoldersAndFiles(){ …. }
public void addSubFolderAndFiles(BaseFileSystem fileObj) { …. }
public void executable(){throw new UnsupportedOperationException();}
}此外,任何有关此类设计问题的一般性建议都将不胜感激。
发布于 2011-04-01 13:36:52
有三个基本的操作,这是缺失的:
BaseFileSystem是File还是File另一方面,我认为有些操作对于文件系统来说不是必需的:
public void executable()似乎不合适。但这只是一个猜测,因为我不知道这个方法应该做什么。如果这会执行一个可执行文件:这应该由操作系统手动完成。此外,它与在类文件夹中定义的业务无关。此外,您在BaseFileSystem中定义的属性对文件系统的要求做了一些假设。也许您的简单权限系统是不够的,或者需要文件系统和ACL的用途。也许可见性是由文件名决定的(就像在UNIX中一样)。你应该事先澄清这一点。
发布于 2011-04-01 13:08:44
根据我对面试问题的了解,你需要确保你提出了关于文件系统的澄清问题。像这样的问题的隐藏部分是为了确保你是一个能够识别歧义的人。还要弄清楚你的用户可能是谁,因为他们可能不关心“修改日期”。
当我读到这个问题时,我在想一些基于*nix的东西,并使用命令行!祝好运!
发布于 2011-04-11 17:00:19
我不认为仅仅提供一个API是有意义的。如果您遵循POSIX,API已经提供给您。描述文件系统的数据模型不是更有意义吗?例如,如何链接数据、跟踪已用/空闲块、处理修改等。
我也不喜欢这样:
因此,上面的每个属性都有public get()和public void set() */
我真的很讨厌getter/setter。如果我要设计一个文件系统,我会将任何文件元数据推送到文件系统之外。而是为任意元数据提供一个通用接口。例如,权限在嵌入式系统上可能无关紧要,那么为什么要使其成为文件系统的一部分呢?
祝好运!
https://stackoverflow.com/questions/5509353
复制相似问题