所有,
我最近在一次技术访谈中被要求为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();}
}
Run Code Online (Sandbox Code Playgroud)
此外,非常感谢任何关于此类设计问题的一般指示.
缺少三项基本操作:
BaseFileSystem是a File还是aFolder另一方面,有些操作我认为对文件系统不重要:
public void executable()似乎不合适.但这只是猜测,因为我不知道这种方法应该做什么.如果这执行可执行文件:应由操作系统手动完成.此外,它没有在类Folder中定义业务.此外,您定义的属性BaseFileSystem会对文件系统的要求做出一些假设.也许您的简单权限系统不够,或者需要文件系统和ACL的目的.可能的可见性取决于文件的名称(如在UNIX中).你应事先澄清一下.