To manage an online streaming service's inventory of shows, we can define a base class representing a general media item and then create subclasses for specific types of shows. Here’s a simple design with two primary classes and some subclasses:
Class Structure
-
MediaItem (Base Class)
- This class represents a general media item. It contains attributes and methods that are common to all types of shows/movies.
class MediaItem: def __init__(self, title, release_year, genre, duration): self.title = title self.release_year = release_year self.genre = genre self.duration = duration # in minutes self.is_available = True def mark_as_unavailable(self): self.is_available = False def mark_as_available(self): self.is_available = True def get_info(self): return f"{self.title} ({self.release_year}) - Genre: {self.genre}, Duration: {self.duration} min"
-
Show (Subclass of MediaItem)
- Represents a general television show. This class may include season and episode details.
class Show(MediaItem): def __init__(self, title, release_year, genre, duration, seasons): super().__init__(title, release_year, genre, duration) self.seasons = seasons # A list of Season objects def get_show_info(self): return f"{self.get_info()}, Seasons: {len(self.seasons)}"
- Subclasses:
-
Series (Subclass of Show)
- Represents a continuous storyline show with multiple episodes per season.
class Series(Show): def __init__(self, title, release_year, genre, duration, seasons, episodes_per_season): super().__init__(title, release_year, genre, duration, seasons) self.episodes_per_season = episodes_per_season # Dictionary with season numbers and episodes def get_series_info(self): return f"{self.get_show_info()}, Episodes per season: {self.episodes_per_season}"
-
Miniseries (Subclass of Show)
- Represents a limited series that usually has fewer episodes and a defined number of seasons.
class Miniseries(Show): def __init__(self, title, release_year, genre, duration, seasons, total_episodes): super().__init__(title, release_year, genre, duration, seasons) self.total_episodes = total_episodes # Total number of episodes in the miniseries def get_miniseries_info(self): return f"{self.get_show_info()}, Total episodes: {self.total_episodes}"
-
-
Movie (Subclass of MediaItem)
- Represents a standalone movie. This class has no seasons or episodes, just the movie attributes.
class Movie(MediaItem): def __init__(self, title, release_year, genre, duration, director): super().__init__(title, release_year, genre, duration) self.director = director # Director of the movie def get_movie_info(self): return f"{self.get_info()}, Directed by: {self.director}"
Summary
This structure allows for a clear hierarchy where both shows and movies share common attributes and methods, yet they also have specific details relevant to their types. The design is flexible enough to extend further if needed, such as adding more specific types of shows or additional features like reviews, ratings, or cast information.
Here is how you might create instances of each class:
# Creating an instance of a Movie
movie1 = Movie("Inception", 2010, "Sci-Fi", 148, "Christopher Nolan")
# Creating an instance of a Series
series1 = Series("Breaking Bad", 2008, "Crime", 49, ["Season 1", "Season 2", "Season 3"], {1: 7, 2: 13, 3: 13})
# Creating an instance of a Miniseries
miniseries1 = Miniseries("Chernobyl", 2019, "Drama", 60, ["Season 1"], 5)
print(movie1.get_movie_info())
print(series1.get_series_info())
print(miniseries1.get_miniseries_info())
This design can be expanded with further functionalities such as adding reviews, ratings, or more complex inventory management features depending on the requirements of the streaming service.