Question

python
Imagine that you are creating a program that an online streaming service will use to manage its inventory of shows. Describe at least two classes that you would create and several subclasses.



Answers

Answered by GPT-4o mini
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

1. **Base Class: `Show`**
- This class will represent a generic show and include common attributes and methods that all shows will share.

2. **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

```python
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 like `title`, `genre`, `release_year`, and `duration`, along with a method to get the show info.
- The subclass `Movie` adds a `director` attribute to store the name of the director.
- The subclass `TVSeries` includes attributes specific to a series, such as `total_episodes`.
- The `Documentary` subclass adds an attribute `subject` to indicate the focus of the documentary.
- `MiniSeries` inherits from `TVSeries` 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.
There are no human answers yet. A form for humans to post answers is coming very soon!

Related Questions