Technical Interview - File System
Problem Statement
Create functions and data structure that can mimic Linux file system commands:
- ls
- mkdir
- readFile
- appendToFile
Assumptions:
- All functions are using full path
- File content is only String
Considerations
Exceptions:
- File not found
- Directory not found
- File cannot be opened
- Directory is a file
- Empty path
- Not enough permission
Class Structure
Patterns:
- Abstract factory (Filesystem)
- Command (FilesystemCommand)
Class diagram:
Utility functions:
String[] splitPath(String fullPath)
String isValidPath(String fullPath)
Reasoning for interfaces:
- Directory - there are other types of directory, such as symlinked directory, network directory, etc
- Files - there are different type of file, such as sockets
- Filesystem - abstract factory will separate concrete types of directory and file from the command, allowing for more extensibility and maintainability