Practice/Amazon/Design Amazon Music
Object Oriented DesignMust
Design an object-oriented system for a music streaming platform that enables users to stream songs, manage playlists, maintain a personal music library, and download content for offline listening. Your design should support core functionality including song playback control, user library management with favorites, playlist creation and manipulation, search capabilities, and offline download management with storage tracking.
The system should handle multiple concurrent users, each with their own libraries and playlists. Consider how different components interact: the music player for playback control, the download manager for offline access, user profiles for personalization, and the overall service coordination.
Example 1: Basic Music Playback
` service = MusicStreamingService() song = Song("s1", "Imagine", "John Lennon", "Imagine", 183, 5) service.add_song(song)
player = MusicPlayer() result = player.play(song)
`
Example 2: Playlist Management
` playlist = Playlist("p1", "Rock Classics", "user1") song1 = Song("s1", "Stairway to Heaven", "Led Zeppelin", "IV", 482, 12) song2 = Song("s2", "Hotel California", "Eagles", "Hotel California", 391, 10)
playlist.add_song(song1) playlist.add_song(song2)
playlist.shuffle()
playlist.remove_song("s1")
`
Example 3: User Library with Favorites
` user = User("u1", "Alice", "alice@example.com") user.add_to_library(song1) user.add_to_library(song2) user.add_to_library(song3)
user.mark_favorite("s1") user.mark_favorite("s3")
favorites = user.get_favorites()
`
Example 4: Search Operations
` service.add_song(Song("s1", "Bohemian Rhapsody", "Queen", "A Night at the Opera", 354, 9)) service.add_song(Song("s2", "We Will Rock You", "Queen", "News of the World", 122, 3)) service.add_song(Song("s3", "Love Story", "Taylor Swift", "Fearless", 235, 6))
results = service.search_by_artist("Queen")
results = service.search_by_title("Love")
`
Example 5: Offline Downloads
` download_mgr = DownloadManager(max_storage_mb=100) song1 = Song("s1", "Title1", "Artist1", "Album1", 180, 5) # 5MB song2 = Song("s2", "Title2", "Artist2", "Album2", 200, 8) # 8MB
success = download_mgr.download_song(song1) # True, 5MB used success = download_mgr.download_song(song2) # True, 13MB used
storage_used = download_mgr.get_storage_used() # Returns 13 downloaded = download_mgr.get_downloaded_songs() # Returns [song1, song2] `