Problem statement
Design the object model and core APIs for a photo album organizer that lets one person group photos into nested albums and browse them in different orders.
Operating context. One user, single in-process service. A library holds photos, each with an id, filename, capture time, and metadata. Albums contain photos and sub-albums, forming a tree. A single photo may belong to several albums at once, held by reference rather than copied. Each album has a display sort order (by capture time, by filename, or manual), and manual order lets the user drag photos into an explicit position. Moving a photo between albums must never duplicate its pixels or metadata.
Out of scope. Image file storage, thumbnail generation, EXIF parsing, face recognition or auto-tagging, cloud upload, and sharing or access permissions.
What to produce. The class hierarchy (library, photo, album, sort strategy), the public API each class exposes, and how album containment is modeled. Be explicit about: the composite structure for nested albums, the many-to-many photo-to-album membership that stores each photo once, how the sort order is a pluggable strategy including a manual order, and how the design prevents an album cycle where an album would contain one of its own ancestors.
Functional requirements
- Create nested albums and add or remove sub-albums, forming a tree.
- Add a photo to one or more albums by reference and remove it from an album without deleting the photo.
- List an album's photos in a chosen sort order: capture time, filename, or manual.
- Move a photo from one album to another and reorder photos within a manually sorted album.
- Count the photos in an album, optionally including its descendant albums.
Non-functional requirements
- Adding or removing a photo from an album is O(1) amortized.
- The sort order is a pluggable strategy so a new ordering needs no change to Album.
- Album containment must reject cycles; an album can never become its own ancestor.
- A photo referenced by many albums stores its pixels and metadata exactly once, never per album.
- The object model is unit-testable without image files or a filesystem.
Topics
- System Design LLD
- Media Photos
- Patterns Composite
- Patterns Strategy
- Oop Solid