To manage the inventory of shows for an online streaming service, we can design a class structure with a base class and several subclasses that represent specific types of shows. Below are two main classes and their respective subclasses.
Class Structure
-
Base Class:
Show
- This class will represent a generic show and include common attributes and methods that all shows will share.
-
Subclasses of
Show
:Movie
- Represents individual movies.
TVSeries
- Represents television series containing multiple episodes.
Documentary
- Represents documentary films or series.
MiniSeries
- Represents a limited series with a predetermined number of episodes.
Class Implementation
class Show:
def __init__(self, title, genre, release_year, duration):
self.title = title
self.genre = genre
self.release_year = release_year
self.duration = duration # Duration in minutes
def get_info(self):
return f"{self.title}, Genre: {self.genre}, Released: {self.release_year}, Duration: {self.duration} mins"
class Movie(Show):
def __init__(self, title, genre, release_year, duration, director):
super().__init__(title, genre, release_year, duration)
self.director = director
def get_info(self):
return super().get_info() + f", Director: {self.director}"
class TVSeries(Show):
def __init__(self, title, genre, release_year, duration_per_episode, total_episodes):
super().__init__(title, genre, release_year, duration_per_episode)
self.total_episodes = total_episodes
def get_info(self):
return super().get_info() + f", Total Episodes: {self.total_episodes}"
class Documentary(Show):
def __init__(self, title, genre, release_year, duration, subject):
super().__init__(title, genre, release_year, duration)
self.subject = subject
def get_info(self):
return super().get_info() + f", Subject: {self.subject}"
class MiniSeries(TVSeries):
def __init__(self, title, genre, release_year, duration_per_episode, total_episodes):
super().__init__(title, genre, release_year, duration_per_episode, total_episodes)
self.is_mini_series = True
def get_info(self):
return super().get_info() + f", Mini-Series: Yes"
# Example usage:
if __name__ == "__main__":
movie = Movie("Inception", "Sci-Fi", 2010, 148, "Christopher Nolan")
series = TVSeries("Breaking Bad", "Drama", 2008, 47, 62)
documentary = Documentary("Planet Earth", "Nature", 2006, 50, "Natural World")
mini_series = MiniSeries("Chernobyl", "Drama", 2019, 60, 5)
print(movie.get_info())
print(series.get_info())
print(documentary.get_info())
print(mini_series.get_info())
Explanation of Design
- The base class
Show
encapsulates common attributes liketitle
,genre
,release_year
, andduration
, along with a method to get the show info. - The subclass
Movie
adds adirector
attribute to store the name of the director. - The subclass
TVSeries
includes attributes specific to a series, such astotal_episodes
. - The
Documentary
subclass adds an attributesubject
to indicate the focus of the documentary. MiniSeries
inherits fromTVSeries
but can flag itself as a mini-series, which helps distinguish it from regular series.
This structure allows for easy expansion in the future; for example, we could add subclasses for animated shows, reality shows, or children's programming with minimal modifications to the base class.