Task and TaskManager Classes (Capstone)
Every application manages collections of things: inventory items, user profiles, support tickets, or todo tasks. This capstone teaches you how professionals structure such systems using OOP. Instead of manually typing 200+ lines of code, you'll work at a higher level: planning the architecture with AI, having it generate code, then validating and extending the design. This mirrors how production systems are built.
Key shift: You focus on design decisions and validation. AI handles typing and syntax details.
Part 1: Plan Task System Architecture with AI
Your Role: System designer collaborating with AI to plan (not write formal specs - just plain language design thinking)
Planning Exercise: Design Your Task Management System
You'll have a design conversation with AI about what you want to build. No formal specs - just system design thinking.
💬 AI CoLearning Prompt - Initial System Design
"I want to build a todo task management system. Help me think through the design (don't write code yet, just help me plan):
What I want:
- Task items that track title, description, priority, and completion status
- A TaskManager that stores multiple tasks and lets me search by title
- Tasks should validate that priority stays between 1-10
- Mark tasks complete and update priorities
- Get a readable string representation of tasks
Help me decide:
- Should I have a Task class for individual items and a separate TaskManager class? Why?
- How do I prevent invalid priority values (negative, over 10)?
- What methods should Task have? (create, complete, modify priority, display)
- What methods should TaskManager have? (add, find, list, maybe filter by priority)
- How should tasks display themselves as text?
- How should I structure this so I can extend it later (recurring tasks, due dates)?
Give me a simple design plan with class structure and responsibilities. Use plain language, not technical jargon."
Expected AI Output: A plain-language plan explaining:
- Task class = individual todo item with validation
- TaskManager class = container managing multiple tasks (composition)
- Methods for both classes with clear responsibilities
- Validation strategy (properties or validation in methods)
- Design rationale in simple terms
Your task: Read AI's plan. Does the design make sense? Can you visualize how the classes work together? What questions do you have?
Challenge AI's Design with "What If" Scenarios
Now test if AI thought through edge cases:
💬 AI CoLearning Prompt - Edge Case Planning
"I like your plan, but I need to think through some real-world scenarios:
Scenario 1: Someone tries to create a Task with priority 15. What should happen? Scenario 2: User marks a task complete, then wants to unmark it later. How should that work? Scenario 3: User searches for a task with title "Buy Milk" but all titles are case-sensitive. What if they search "buy milk"? Exact match only or fuzzy? Scenario 4: Two tasks have the same title. Should find_by_title return the first match, all matches, or raise an error? Scenario 5: TaskManager is empty. What should list_tasks() return?
For each, explain what makes sense from a user perspective. How should my design handle these cases?"
Expected Learning: AI will explain design patterns (validation with exceptions, stateful properties, case-insensitive search, defensive programming). You're learning design thinking, not just coding syntax.
Your Simple Design Plan
After your conversation with AI, write down a simple plan:
My Task System Design Notes:
-
Task class = individual todo item
- title (required, non-empty)
- description (optional)
- priority (1-10, defaults to 5)
- status ("pending" or "completed")
- done (True/False boolean)
- Methods: mark_complete(), update_priority(new_priority)
- Methods: repr() for display, eq() for comparison
-
TaskManager class = manages multiple Task objects
- tasks list (collection of Task instances)
- Methods: add_task(task), list_tasks(), find_by_title(title)
- Methods: remove_task(task), maybe filter_by_priority(priority)
-
Validation:
- Priority must be 1-10 (enforce in update_priority method)
- Title can't be empty
- Status/done track completion state
-
Design principles:
- Task HAS-A data (title, priority, etc.)
- TaskManager HAS-A collection of Tasks (composition)
- Methods modify state safely (encapsulation)
Key Learning: You planned the ARCHITECTURE through conversation, not by writing formal specs. That skill comes later in Part 5.
Deliverable: Simple task system design notes from your AI conversation. You've planned the architecture - now AI will help generate the implementation.
Part 2: Generate Code and Validate Design
Your Role: Design validator working with AI to generate and refine the system
AI-Assisted Implementation
Instead of typing 200+ lines manually, you'll have AI generate the system, then YOU validate it against your design plan.
💬 AI CoLearning Prompt - Generate Task and TaskManager Classes
"Based on my task management design plan, generate the complete Python code:
Task Class Requirements:
- Attributes: title (str), description (str, default ""), priority (int, default 5), status (str, default "pending"), done (bool, default False), due_date (optional)
- Constructor: init(self, title: str, description: str = "", priority: int = 5)
- Methods:
- mark_complete() → sets done to True, status to "completed"
- update_priority(new_priority: int) → validates 1-10, raises ValueError if invalid
- repr() → returns readable string like "[✓] Buy milk (P2)" or "[○] Buy milk (P2)"
- eq(other) → compares tasks by title
- Use type hints on all methods
- Use docstrings for all methods
TaskManager Class Requirements:
- Attributes: tasks (list of Task objects, empty initially)
- Methods:
- add_task(task: Task) → adds task to list
- list_tasks() → returns copy of tasks list
- find_by_title(title: str) → returns Task if found, None otherwise
- remove_task(task: Task) → removes from list, returns True if found
- count_completed() → returns number of done tasks
- Use type hints and docstrings
Generate complete working code. I'll validate it against my design."
Expected AI Output: ~80-120 lines of complete code implementing both classes.
Validation Exercise: Check AI's Implementation
Your task: Read the AI-generated code and validate these design decisions:
✅ Validation Checklist:
-
Class Structure:
- Does Task have all required attributes? ✓
- Does Task have all required methods? ✓
- Does TaskManager exist as separate class? ✓
- Is TaskManager's tasks list initialized as empty list? ✓
-
Encapsulation (Lesson 4 concept):
- Does update_priority validate that 1 is less than or equal to priority and priority is less than or equal to 10? ✓
- Does update_priority raise ValueError with clear message? ✓
- Does mark_complete set both done and status correctly? ✓
-
String Representation:
- Does repr show meaningful info (title, done status, priority)? ✓
- Does repr use symbols like ✓ and ○ for visibility? ✓
- Does eq compare by title (two tasks with same title are equal)? ✓
-
Type Hints (Chapter 27 standard):
- Does every method have parameter type hints? ✓
- Does every method have return type hints? ✓
- Does Task.eq return bool? ✓
-
TaskManager Composition:
- Does TaskManager HAS-A collection of Task objects? ✓
- Do methods return appropriate types (Task | None, list[Task], bool)? ✓
-
Edge Cases (from Part 1 planning):
- Does find_by_title return None if not found? ✓
- Does list_tasks return copy (not reference to internal list)? ✓
- Does update_priority handle invalid values with exception? ✓
Example Code (What AI Generated)
Loading Python environment...
Output Examples:
Loading Python environment...
Challenge AI with Edge Cases
💬 AI CoLearning Prompt - Validate Edge Cases
"Validate your code handles these edge cases:
Test 1: Empty Title Prevention
Loading Python environment...
Test 2: Priority Validation
Loading Python environment...
Test 3: Equality Comparison
Loading Python environment...
Test 4: TaskManager with Empty List
Loading Python environment...
Test 5: Remove Non-existent Task
Loading Python environment...
Run these tests and show me output. Do they all work as expected?"
Expected Learning: You validate AI's implementation through testing, not by reading every line. Professional workflow = specify → generate → validate.
Your task: Write and test the implementation:
- Create Task objects with valid and invalid parameters
- Create TaskManager and add multiple tasks
- Test find_by_title, filter_by_priority, count_completed
- Test edge cases (empty title, invalid priority, nonexistent tasks)
- Document what works and what needs refinement
Deliverable: Fully functional task system passing all validation tests.
Part 3: Challenge AI with "What If" Extensions
Your Role: System designer testing design flexibility
Extension Challenge Exercise
Now that you have a working system, challenge AI to extend it. Can the design handle new features without major refactoring?
💬 AI CoLearning Prompt - Add Recurring Tasks
"I want to add recurring tasks to my system. Recurring tasks repeat on a schedule (daily, weekly, monthly):
Requirements:
- Recurring task repeats until marked complete or cancelled
- Has: title, description, priority, recurrence_pattern ('daily', 'weekly', 'monthly')
- Methods: same as Task, plus next_occurrence() that returns when task recurs
- When marked complete, should create a new instance for next occurrence
Design options:
- Add recurrence_pattern to Task class (all tasks have it, even if null)?
- Create RecurringTask subclass inheriting from Task?
- Create separate Task and RecurringTask classes both managed by TaskManager?
Which design is better? Show me the code for your recommendation. Explain trade-offs."
Expected Learning: AI will show you how to extend your system through inheritance or composition. You'll see if your original design was flexible.
💬 AI CoLearning Prompt - Priority Filtering and Sorting
"I want to display tasks sorted by priority (highest first). Currently I have filter_by_priority() which returns a list.
Options:
- Add get_high_priority_tasks() method returning tasks with priority 1-3?
- Add sort_by_priority() to TaskManager returning sorted list?
- Implement custom comparator for Task so I can use Python's sorted() function?
Which is most Pythonic? Show me code for the best approach. What would production code do?"
Expected Learning: AI introduces Python's built-in sorting mechanisms and design patterns for filtering/sorting collections.
💬 AI CoLearning Prompt - Add Due Date Support
"I want tasks to have due dates and show overdue status:
- Task has optional due_date (datetime or None)
- is_overdue() method returns True if done=False and due_date < today
- TaskManager has get_overdue_tasks() returning tasks past deadline
How should due dates affect priority sorting? Should overdue tasks always sort first? Show me implementation with datetime usage."
Expected Learning: You see how object attributes and methods interact with real-world domain concepts (dates, deadlines).
Your Extensions
Implement 1-2 new features with AI assistance:
- Recurring tasks (inheritance approach with RecurringTask subclass)
- Priority-based sorting (custom methods or sorting support)
- Due date support (datetime integration)
- Task templates (create common tasks from patterns)
Deliverable: Extended task system with 1-2 new features generated and validated through AI.
Part 4: Build Your OOP Design Framework
Your Role: Experienced designer extracting lessons learned
Reflection Exercise
After building and extending your system with AI, extract the design patterns you learned.
💬 AI CoLearning Prompt - Synthesize Design Patterns
"Based on my Task Management System project, help me create a design guide for future OOP projects:
What I learned:
- When to create separate classes vs add attributes to existing class
- When to use composition (TaskManager HAS-A list of Tasks) vs inheritance (RecurringTask IS-A Task)
- How to design for validation and prevent invalid states
- How to use repr and eq for meaningful object behavior
- How to structure classes so they're easy to extend
Give me a framework with:
- When to use each design pattern
- Common mistakes to avoid
- Quick decision guide ('If X, use Y')
- Examples from my task system
Use my actual project as examples throughout."
Expected AI Output: A personalized OOP design guide based on your project experience.
Your OOP Design Framework
Save AI's framework as your reference. Example structure:
My OOP Design Guide (From Task System Project):
Single Responsibility Principle:
- Task class = manages single task (title, priority, completion, validation)
- TaskManager class = manages collection of tasks (add, find, list, filter)
- Each class has one reason to change
When to Use Composition (HAS-A):
- TaskManager HAS-A list of Task objects
- "Does X contain Y?" → Yes, use composition
- Composition is more flexible than inheritance
- Example: RecurringTask HAS-A base Task pattern
When to Use Inheritance (IS-A):
- RecurringTask IS-A Task (shares all Task behavior)
- "Is X a specialized version of Y?" → Yes, use inheritance
- Subclasses inherit constructor, methods, validation
- Example: RecurringTask adds recurrence_pattern, next_occurrence()
String Representation and Comparison:
- repr() makes Task display nicely: "[✓] Title (P5)"
- eq() enables "task1 == task2" comparison by meaningful attribute
- Essential for debugging and testing
Design for Extensibility:
- Use clear method names and consistent signatures
- Design validation in constructors and methods (update_priority checks range)
- Use type hints so subclasses know expected types
- Composition is often more flexible than inheritance
Common Mistakes I Avoided:
- Making everything inherit (sometimes composition is simpler)
- Forgetting validation (prevented invalid states)
- Not planning for extensions (able to add recurring tasks easily)
- Exposing internal data directly (return .copy() for lists)
Deliverable: Personal OOP design framework extracted from your project. You've learned by building, not just reading.
Part 5: AI Validation and Professional Polish
Your Role: Engineer ensuring production quality
Final Validation Exercise
Ask AI:
"Final review: Does my Task Management System demonstrate:
- Proper use of OOP principles (encapsulation, composition, type hints)?
- Professional Python style (naming, docstrings, error handling)?
- Robust validation and edge case handling?
- Clear class responsibilities and method design?
- Extensibility for future features?
Give me a final checklist of what would make this production-ready and how I'm meeting those standards."
Your Final Deliverables
- task_system_specification.md - Full design specification from Part 1
- task_manager_system.py - Complete Task and TaskManager classes
- ai_review_feedback.md - AI's code review and your responses
- extended_system.py - One implemented extension (RecurringTask or DueDate support)
- production_checklist.md - Production-readiness criteria and how you meet them
Real-World Applications
The Task + TaskManager pattern appears everywhere:
Legal Domain:
Loading Python environment...
Finance Domain:
Loading Python environment...
Healthcare Domain:
Loading Python environment...
Key Insight: Once you master the Task + Manager pattern, you can apply it anywhere: Projects + ProjectManager, Tickets + TicketManager, Users + UserManager. This is fundamental OOP architecture.
Transition to Chapter 29
Objects organize your task data beautifully. Your system is properly structured with clear separation of concerns. In Chapter 29, you'll learn about dataclasses, which are Python's way of making classes like Task even simpler to define while keeping all the power:
Loading Python environment...
Same functionality, better syntax. Your understanding of classes and objects is the foundation.
Try With AI
Ready to design and build a task management system that demonstrates OOP mastery?
🏗️ Design the Architecture:
"I want to build a task management system. Help me design: should I have a Task class for individual items and a TaskManager class for the collection? What methods does each need? What validation should prevent invalid tasks? Draw me a simple class diagram or structure."
What you're learning: Architectural thinking - how to organize classes and their relationships before writing code. This is how professionals approach OOP projects.
💻 Build the Foundation:
"Build me a Task class with: title (required), description (optional), priority (1-10, defaults to 5), and done status (boolean). Include an init method, a mark_complete() method, and a repr() that shows '[✓] Title (P5)' or '[○] Title (P5)'. Use type hints and validation in update_priority() method. Show test code creating two tasks and marking one complete."
What you're learning: Class structure with proper initialization, validation, and methods that safely modify state. This is encapsulation in practice.
🔍 Extend the System:
"Add a TaskManager class that manages a collection of Task objects. Include: add_task(task), list_tasks(), find_by_title(title) returning Task or None, count_completed() showing how many tasks are done. Show me code that creates a TaskManager, adds 3 tasks, finds one by title, marks it complete, and shows the count."
What you're learning: Composition pattern - TaskManager HAS-A collection of Task objects. This shows how real systems are built from interacting classes.
⚙️ Validate Design Decisions:
"Test my Task system for edge cases: (1) Creating task with empty title should fail, (2) Priority 15 should raise error, (3) Two tasks with same title should be equal (task1 == task2), (4) Marking complete should set both done=True and status='completed'. Show me test code and expected outputs."
What you're learning: Design validation through testing. Professional workflow = design → generate → test → refine.
🚀 Plan an Extension:
"I want to add a RecurringTask that repeats daily/weekly/monthly. Should RecurringTask inherit from Task or be separate? What new methods does it need? How does TaskManager handle both regular and recurring tasks? Show me a design comparison of inheritance vs composition for this feature."
What you're learning: Advanced design patterns and trade-offs. How good designs remain flexible when requirements change.