Challenge: The Single Responsibility Principle

Test your knowledge of using the Single Responsibility Principle to improve your code.

We'll cover the following

Overview

Refactor the given Student class, which currently has too many responsibilities. Use the Single Responsibility Principle (SRP) so that the class handles only a single responsibility.

Requirements

Our code currently consists of three files, main.py, classes.py, and data.py. We have two classes within classes.py: Student and SemesterResult.

We create instances of Student and test the classes in main.py by using the data provided in data.py.

The class Student currently is responsible for multiple responsibilities, and thus violates the SRP. Identify the different responsibilities undertaken by the class and refactor the code so that it adheres to the SRP. Divide the responsibilities into separate classes if needed.

Get hands-on with 1200+ tech skills courses.