Skip to content

Latest commit

 

History

History
137 lines (102 loc) · 3.44 KB

File metadata and controls

137 lines (102 loc) · 3.44 KB

Designing a Task Management System

In this article, we explore the design and implementation of a Task Management System using Python3, with a focus on object-oriented principles.

The system allows users to create, manage, and track tasks effectively.

System Requirements

The Task Management System should:

  1. Task Creation and Management: Enable users to create, update, and delete tasks.
  2. User Management: Manage user accounts and associated tasks.
  3. Task Assignment: Allow tasks to be assigned to specific users.
  4. Task Tracking: Track the progress and status of tasks.
  5. Notifications: Notify users about task deadlines and updates.

Core Use Cases

  1. Managing User Accounts
  2. Creating and Updating Tasks
  3. Assigning Tasks to Users
  4. Tracking Task Progress
  5. Sending Notifications

Key Classes:

  • TaskManagementSystem: Manages the overall system.
  • User: Represents a system user.
  • Task: Represents a task.
  • TaskStatus: Enum for task status.

Python3 Implementation

User Class

Manages user account information.

class User:
    def __init__(self, user_id: str, name: str):
        self.user_id = user_id
        self.name = name
        self.assigned_tasks = []

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

Task Class

Represents a task.

from datetime import datetime
from enum import Enum

class TaskStatus(Enum):
    PENDING = 'PENDING'
    IN_PROGRESS = 'IN_PROGRESS'
    COMPLETED = 'COMPLETED'
    CANCELLED = 'CANCELLED'

class Task:
    def __init__(self, task_id: str, title: str, due_date: datetime):
        self.task_id = task_id
        self.title = title
        self.description = ""
        self.due_date = due_date
        self.status = TaskStatus.PENDING

    def update_status(self, new_status: TaskStatus):
        self.status = new_status

TaskManagementSystem Class

Manages task management operations.

class TaskManagementSystem:
    def __init__(self):
        self.users = {}
        self.tasks = {}

    def add_user(self, user: User):
        self.users[user.user_id] = user

    def add_task(self, task: Task):
        self.tasks[task.task_id] = task

    def assign_task_to_user(self, task_id: str, user_id: str):
        user = self.users.get(user_id)
        task = self.tasks.get(task_id)
        if user and task:
            user.add_task(task)

    def find_user_by_id(self, user_id: str):
        return self.users.get(user_id)

    def find_task_by_id(self, task_id: str):
        return self.tasks.get(task_id)

Example Usage

def main():
    # Initialize task management system
    system = TaskManagementSystem()

    # Create users
    alice = User("u001", "Alice")
    bob = User("u002", "Bob")

    # Add users to the system
    system.add_user(alice)
    system.add_user(bob)

    # Create tasks
    task1 = Task("t001", "Finish the report", datetime(2023, 12, 31))
    task2 = Task("t002", "Prepare meeting agenda", datetime(2023, 12, 15))

    # Add tasks to the system
    system.add_task(task1)
    system.add_task(task2)

    # Assign tasks to users
    system.assign_task_to_user("t001", "u001")
    system.assign_task_to_user("t002", "u002")

    # Display task assignments
    for task in alice.assigned_tasks:
        print(f"Alice has assigned: {task.title}")

    for task in bob.assigned_tasks:
        print(f"Bob has assigned: {task.title}")

if __name__ == "__main__":
    main()