gpt4 book ai didi

filesystems - 面试 Q - 设计文件系统 - 回顾

转载 作者:行者123 更新时间:2023-12-04 01:03:13 26 4
gpt4 key购买 nike

关闭。这个问题需要更多focused .它目前不接受答案。












想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post .

2年前关闭。




Improve this question




全部,

最近在一次技术面试中,我被要求为文件系统编写高级设计。我对这个问题的回答如下。我会请求大家请审查,如果有建议/改进,请告诉我:

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

此外,将不胜感激任何指向此类设计问题的一般指针。

最佳答案

缺少三个基本操作:

  • 读取文件内容
  • 写入文件内容
  • 测试是否为 BaseFileSystemFileFolder

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

  • 此外,您在 BaseFileSystem 中定义的属性对文件系统的要求做一些假设。也许您的简单权限系统还不够,或者需要文件系统和 ACL 的用途。也许可见性由文件的名称决定(如在 UNIX 中)。你应该事先澄清这一点。

    关于filesystems - 面试 Q - 设计文件系统 - 回顾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5509353/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com