222.2 Class design / TaskManager

This section outlines the design of the TaskManager class, which is responsible for storing and managing multiple Task objects.

Role of the TaskManager class

The TaskManager class is responsible for coordinating and controlling the list of tasks. It provides a structured way to store, access, and manipulate multiple Task objects. While the Task class handles individual task behaviour, the TaskManager class handles the collection and interaction between tasks.

Attributes

The TaskManager class uses a single instance attribute:

  • tasks: a list that stores multiple Task objects

This list allows the program to keep track of all active tasks and iterate through them when performing operations like searching, displaying, or filtering.

Methods

The TaskManager class provides the following behaviours:

  • add_task(task) – adds a new Task object to the list

  • list_tasks() – displays a summary of all tasks

  • find_task(title) – searches for a task by title and returns the Task object

  • remove_task(title) – removes a task from the list based on title

  • get_completed_tasks() – returns a list of completed tasks

  • get_incomplete_tasks() – returns a list of incomplete tasks

  • display_all_tasks() – calls display_details() for each task

These methods support key user actions such as adding, viewing, and managing task progress.

Sample interface

This sketch shows a basic version of the class and its interface:

class TaskManager:
    def __init__(self):
        self.tasks = []

    def add_task(self, task):
        self.tasks.append(task)

    def list_tasks(self):
        for task in self.tasks:
            task.display_summary()

    def find_task(self, title):
        for task in self.tasks:
            if task.title == title:
                return task
        return None

    def remove_task(self, title):
        task = self.find_task(title)
        if task:
            self.tasks.remove(task)

    def get_completed_tasks(self):
        return [task for task in self.tasks if task.is_complete]

    def get_incomplete_tasks(self):
        return [task for task in self.tasks if not task.is_complete]

    def display_all_tasks(self):
        for task in self.tasks:
            task.display_details()

Notes on design

The TaskManager acts as a controller class that manages the lifecycle of Task objects. It separates user-level operations from individual object behaviour, supporting a clear and maintainable system structure. Additional features such as filtering, sorting, or saving tasks can be added to this class in future sprints.

Last updated

Was this helpful?