222.1 Class design / Task

This section introduces the Task class, which defines the structure and behaviour of individual tasks in the Task Tracker app.

Role of the Task class

The Task class is responsible for representing a single task in the system. Each task has its own set of data (attributes) and actions (methods). This class forms the foundation of the app by encapsulating all the information and behaviours associated with a task.

Attributes

Each Task object stores the following attributes:

  • title: a short label for the task

  • description: a more detailed explanation

  • due_date: the date by which the task should be completed

  • is_complete: a Boolean value indicating whether the task is completed

These attributes are initialised when a Task object is created.

Methods

The Task class provides the following methods:

  • mark_complete() – sets is_complete to True

  • mark_incomplete() – sets is_complete to False

  • display_summary() – prints a short summary of the task, including title and status

  • display_details() – prints the full details of the task (title, description, due date, status)

These methods allow the object to manage its own state and present its data to the user.

Sample interface

This sketch shows what the class interface might look like when defined in Python:

class Task:
    def __init__(self, title, description, due_date):
        self.title = title
        self.description = description
        self.due_date = due_date
        self.is_complete = False

    def mark_complete(self):
        self.is_complete = True

    def mark_incomplete(self):
        self.is_complete = False

    def display_summary(self):
        status = "✓" if self.is_complete else "✗"
        print(f"{self.title} [{status}]")

    def display_details(self):
        status = "Complete" if self.is_complete else "Incomplete"
        print(f"Title: {self.title}")
        print(f"Description: {self.description}")
        print(f"Due: {self.due_date}")
        print(f"Status: {status}")

Notes on design

The Task class is designed to be lightweight and self-contained. It handles its own data and behaviours and does not rely on global variables or external functions. Future enhancements such as categories, priorities, or tags could be added later as additional attributes.

Last updated

Was this helpful?