File System LLD: The Composite Pattern's Home Turf
A low-level design walkthrough of an in-memory file system: files and directories behind one Node interface, path resolution as a walk, recursive size via the Composite pattern — fully implemented.
"Design an in-memory file system." (LeetCode knows it as #588; interviewers know it as a forty-minute X-ray of how you handle trees.) The question looks like it's about mkdir and ls — but it's really asking one design riddle: a directory contains files and other directories. What's the type of "thing a directory contains"? Answer that one question well and every operation — sizes, listings, deletes — collapses into a few lines of recursion. Answer it badly (two parallel maps, instanceof everywhere) and each new feature doubles your code. The good answer has a name — the Composite pattern — and…
What’s inside
Read this one free
Sign in and your first premium article is on us — read File System LLD: The Composite Pattern's Home Turf free.