Design File Explorer in IDE
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2021-11-19
Problem Statement
Design a File Explorer module for an Integrated Development Environment (IDE). The focus is on object-oriented design, modularity, file system abstraction, and operations on files/folders.
✅ Functional Requirements
1.File System Representation
•Represent files and directories in a tree-like structure.
•Support operations like create, read, update, delete (CRUD) for files and directories.
2.Navigation
•Expand/collapse folders to view nested files/directories.
•Maintain current path and selection state.
3.File Operations
•Open, rename, move, copy, and delete files/directories.
•Support drag-and-drop functionality (optional).
4.Search & Filter
•Search files/folders by name or extension.
•Optionally filter by file type or recent modifications.
5.Integration
•Interface with IDE editor to open files.
•Optionally show file status (e.g., modified, unsaved changes, version control status).
🔐 Constraints & Assumptions
•Focus is on LLD and modular design, not UI.
•File system can be local or virtual (in-memory).
•Assume synchronous file operations for simplicity; can extend to asynchronous.
🧱 Key Components & Classes
1.FileSystemItem (Abstract Class / Interface)
1
2class FileSystemItem {
3protected:
4 string name;
5 string path;
6public:
7 virtual void rename(string newName) = 0;
8 virtual string getName() = 0;
9 virtual string getPath() = 0;
10};1.File Class
1
2class File : public FileSystemItem {
3private:
4 string content;
5public:
6 void open();
7 void write(string newContent);
8 void rename(string newName);
9};1.Directory Class
1
2class Directory : public FileSystemItem {
3private:
4 vector<FileSystemItem*> children;
5public:
6 void addItem(FileSystemItem* item);
7 void removeItem(FileSystemItem* item);
8 vector<FileSystemItem*> getChildren();
9 FileSystemItem* find(string name);
10};1.FileExplorerController Class
1
2class FileExplorerController {
3private:
4 Directory* root;
5 Directory* currentDirectory;
6public:
7 void navigateTo(string path);
8 void createFile(string name);
9 void createDirectory(string name);
10 void deleteItem(string name);
11 void moveItem(string sourcePath, string destinationPath);
12 vector<FileSystemItem*> listItems();
13};1.Optional: SearchService
•Supports search and filtering of files/folders within the explorer.
🔄 Example Workflow
1.Initialize FileExplorerController with the project root directory.
2.User navigates to a folder: navigateTo("/src").
3.User creates a new file: createFile("Main.cpp").
4.User renames or deletes a file/folder.
5.Optional: search for a file using SearchService.
🧪 Expected Deliverables
•Class diagram showing FileSystemItem, File, Directory, FileExplorerController, and optional SearchService.
•Implementation of CRUD operations on files and directories.
•Test cases:
•Creating, renaming, deleting files/folders
•Navigation between directories
•Searching for files
•Handling edge cases (duplicate names, invalid paths)
💡 Discussion Points
•Trade-offs between in-memory vs OS-backed file system.
•Extensibility for version control integration or IDE-specific features.
•Handling large directories efficiently.
•Optional: asynchronous operations for file IO.