采访Q - 设计文件系统 - 回顾

时间:2011-04-01 05:03:19

标签: filesystems

所有

我最近在一次技术访谈中被要求为File Sysem编写高级设计。我对这个问题的回答如下。如果有任何建议/改进,我会要求大家进行审核并告诉我:

  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();}
}

此外,非常感谢任何有关此类设计问题的一般指示。

3 个答案:

答案 0 :(得分:9)

缺少三项基本操作:

  • 阅读文件内容
  • 撰写文件内容
  • 测试BaseFileSystemFile还是Folder

另一方面,有些操作我认为对文件系统不重要:

  • 文件扩展名在所有操作系统中都没有任何意义。那么为什么要存在设置和检索它的方法呢?
  • 相关程序仅在单个计算机/ os组合中具有含义。在通用文件系统中,程序可能只是暂时存在(因为引导了不同的操作系统或移动了设备)。由于关注点分离,IMHO不应存储为文件元信息的一部分。
  • public void executable()似乎不合适。但这只是猜测,因为我不知道这种方法应该做什么。如果这执行可执行文件:应由操作系统手动完成。此外,它没有在类Folder中定义任何业务。

此外,您在BaseFileSystem中定义的属性会对文件系统的要求做出一些假设。也许您的简单权限系统不够,或者需要文件系统和ACL的目的。可能的可见性取决于文件的名称(如在UNIX中)。你应该事先澄清一下。

答案 1 :(得分:1)

根据我对面试问题的了解,您需要确保要求澄清有关文件系统的问题。这样一个问题的隐藏部分是确保你是一个可以识别歧义的人。还要弄清楚您的用户可能是谁,因为他们可能不关心“修改日期”

当我读到这个问题时,我正在考虑基于* nix的东西,并会使用命令行!祝你好运!

答案 2 :(得分:1)

我认为只提供API是不合理的。如果您关注POSIX,则已经向您提供了API。描述文件系统的数据模型会不会更有意义?例如,如何链接数据,跟踪已用/空闲块,处理修改等...

我也不喜欢这样:

  

因此,上述每个属性都有public get()和public void set()* /

我真的讨厌吸气鬼/二传手。如果我要设计一个文件系统,我会将任何文件元数据推送到文件系统之外。而是为任意元数据提供通用接口。例如,权限可能与嵌入式系统无关,那么为什么要将其作为文件系统的一部分呢?

祝你好运!

相关问题