-
Notifications
You must be signed in to change notification settings - Fork 53
Description
🎯 Task Overview
Task ID: 3.0
Parent Spec: docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.md
Depends On: Task 1.0, Task 2.0 (conceptually independent, but sequential for consistency)
Status: Ready for Implementation
Estimated Time: 2-3 hours
This task implements comprehensive documentation for Classical Gang of Four Patterns (11.2.4), including Strategy, Factory, Observer, and Decorator patterns with working examples distributed across languages, explicit SOLID connections, and an interactive quiz.
📋 Specification Context
Project Overview
This specification defines the remaining Design Patterns subsections for Chapter 11 (Application Development) of the DevOps Bootcamp. This task introduces selected Gang of Four patterns that directly relate to SOLID principles and are commonly used in production applications.
User Story
US-4: Recognizing Classical Patterns
As a senior CSCI student preparing for professional work, I want to recognize Strategy, Factory, Observer, and Decorator patterns in existing codebases so that I can understand and contribute to enterprise projects.
Functional Requirements
| ID | Requirement |
|---|---|
| U4-FR1 | The system shall explain Strategy Pattern with examples demonstrating swappable algorithms and explicit connection to Open/Closed Principle |
| U4-FR2 | The system shall explain Factory Pattern with examples demonstrating object creation abstraction and explicit connection to Dependency Inversion Principle |
| U4-FR3 | The system shall explain Observer Pattern with examples demonstrating event-driven communication between objects |
| U4-FR4 | The system shall explain Decorator Pattern with examples demonstrating behavior extension and explicit connection to Open/Closed Principle |
| U4-FR5 | The system shall organize pattern explanations by problem domain: Creational (Factory), Behavioral (Strategy, Observer), Structural (Decorator) |
| U4-FR6 | The system shall explicitly connect each pattern to relevant SOLID principles with cross-references to 11.2.1 content |
| U4-FR7 | The system shall provide pattern recognition exercises using real-world code snippets |
| U4-FR8 | The system shall include a self-directed exercise for students to identify patterns in a production codebase of their choice |
| U4-FR9 | The system shall include an interactive quiz testing pattern recognition across code snippets in multiple languages |
✅ Acceptance Criteria (Proof Artifacts)
The following artifacts must exist and be verified for task completion:
- Documentation:
docs/11-application-development/11.2.4-classical-patterns.mdexists with complete content including front-matter, pattern explanations organized by category (Creational/Behavioral/Structural), SOLID connections, and exercises - Strategy Pattern:
examples/ch11/classical-patterns/strategy/contains working implementation with README and explicit connection to Open/Closed Principle - Factory Pattern:
examples/ch11/classical-patterns/factory/contains working implementation with README and explicit connection to Dependency Inversion Principle - Observer Pattern:
examples/ch11/classical-patterns/observer/contains working implementation with README demonstrating event-driven communication - Decorator Pattern:
examples/ch11/classical-patterns/decorator/contains working implementation with README and explicit connection to Open/Closed Principle - Quiz:
src/quizzes/chapter-11/11.2.4/classical-patterns-quiz.jsexists with multi-language pattern recognition questions following quizdown format - CLI Verification: Tests pass in all example directories (using appropriate test command per language)
- SOLID Integration: Each pattern README includes explicit cross-reference to relevant section in 11.2.1
📝 Sub-tasks
Documentation Tasks
- 3.1 Create documentation file
docs/11-application-development/11.2.4-classical-patterns.mdwith front-matter (category: Application Development, technologies: Python/Go/TypeScript/Design Patterns, estReadingMinutes: 45, exercise definition) - 3.2 Write introduction explaining Gang of Four patterns, their organization (Creational/Behavioral/Structural), and focus on patterns most relevant to SOLID principles
- 3.3 Write Strategy Pattern section (Behavioral) explaining swappable algorithms, explicit connection to Open/Closed Principle (extending behavior without modification), and cross-reference to 11.2.1
- 3.4 Write Factory Pattern section (Creational) explaining object creation abstraction, explicit connection to Dependency Inversion Principle (depending on abstractions), and cross-reference to 11.2.1
- 3.5 Write Observer Pattern section (Behavioral) explaining event-driven communication, one-to-many dependencies, and use cases (UI updates, event systems)
- 3.6 Write Decorator Pattern section (Structural) explaining dynamic behavior extension, explicit connection to Open/Closed Principle (adding responsibilities without modification), and cross-reference to 11.2.1
- 3.7 Add pattern recognition section with guidance on identifying these patterns in production codebases
- 3.8 Add self-directed exercise description for students to identify patterns in a production codebase of their choice
Code Example Tasks (Multi-Language)
- 3.9 Create Strategy Pattern Python example in
examples/ch11/classical-patterns/strategy/with pyproject.toml, src/ (different algorithm implementations), README.md with OCP connection, and tests - 3.10 Create Factory Pattern Go example in
examples/ch11/classical-patterns/factory/with go.mod, factory.go (creation abstraction), README.md with DIP connection, and tests - 3.11 Create Observer Pattern TypeScript example in
examples/ch11/classical-patterns/observer/with package.json, tsconfig.json, src/ (subject/observer implementation), README.md, and tests - 3.12 Create Decorator Pattern Python example in
examples/ch11/classical-patterns/decorator/with pyproject.toml, src/ (base component + decorators), README.md with OCP connection, and tests
Quiz and Verification Tasks
- 3.13 Create interactive quiz
src/quizzes/chapter-11/11.2.4/classical-patterns-quiz.jswith 8-10 questions covering pattern recognition from code snippets in multiple languages, SOLID connections, and when to use each pattern - 3.14 Verify Strategy and Decorator Python examples run successfully with
uv run main.pyand tests pass withuv run pytest - 3.15 Verify Factory Go example runs successfully with
go run main.goand tests pass withgo test ./... - 3.16 Verify Observer TypeScript example runs successfully with
npm run startand tests pass withnpm test - 3.17 Embed quiz in documentation using Docsify quiz syntax and verify it renders correctly with
npm start
📁 Relevant Files
Files to Create
Documentation:
docs/11-application-development/11.2.4-classical-patterns.md- Main documentationsrc/quizzes/chapter-11/11.2.4/classical-patterns-quiz.js- Interactive quiz
Strategy Pattern (Python):
examples/ch11/classical-patterns/strategy/pyproject.toml- Python dependenciesexamples/ch11/classical-patterns/strategy/src/strategy.py- Strategy interface and implementationsexamples/ch11/classical-patterns/strategy/src/main.py- Executable demoexamples/ch11/classical-patterns/strategy/tests/test_strategy.py- Unit testsexamples/ch11/classical-patterns/strategy/README.md- Setup, explanation, and OCP connection
Factory Pattern (Go):
examples/ch11/classical-patterns/factory/go.mod- Go module definitionexamples/ch11/classical-patterns/factory/factory.go- Factory interface and implementationsexamples/ch11/classical-patterns/factory/main.go- Executable demoexamples/ch11/classical-patterns/factory/factory_test.go- Unit testsexamples/ch11/classical-patterns/factory/README.md- Setup, explanation, and DIP connection
Observer Pattern (TypeScript):
examples/ch11/classical-patterns/observer/package.json- Dependenciesexamples/ch11/classical-patterns/observer/tsconfig.json- TypeScript configexamples/ch11/classical-patterns/observer/src/observer.ts- Observer interfaceexamples/ch11/classical-patterns/observer/src/subject.ts- Subject implementationexamples/ch11/classical-patterns/observer/src/main.ts- Executable demoexamples/ch11/classical-patterns/observer/tests/observer.test.ts- Unit testsexamples/ch11/classical-patterns/observer/README.md- Setup and explanation
Decorator Pattern (Python):
examples/ch11/classical-patterns/decorator/pyproject.toml- Python dependenciesexamples/ch11/classical-patterns/decorator/src/decorator.py- Component interface and decoratorsexamples/ch11/classical-patterns/decorator/src/main.py- Executable demoexamples/ch11/classical-patterns/decorator/tests/test_decorator.py- Unit testsexamples/ch11/classical-patterns/decorator/README.md- Setup, explanation, and OCP connection
Files to Reference
docs/11-application-development/11.2.1-solid-principles.md- SOLID principles (for explicit cross-references)examples/ch11/solid-exercises/- Example of existing code structuresrc/quizzes/chapter-11/11.2.1/solid-principles-quiz.js- Example quiz format to follow
🎓 Repository Standards
Code Example Standards (Multi-Language)
Python (Strategy, Decorator):
- Python 3.11+ with
uvfor dependency management - Use
pyproject.tomlfor project configuration - Testing with pytest:
uv run pytest - Type hints where appropriate
- Follow PEP 8 style guidelines
Go (Factory):
- Go 1.21+ with Go modules
- Standard Go project layout
- Testing with built-in package:
go test ./... - Follow Go best practices (gofmt, golint)
TypeScript (Observer):
- Node.js 20+ with npm/package.json
- TypeScript with strict mode enabled
- Testing with Jest:
npm test - Follow TypeScript best practices
General:
- All examples must be self-contained with README, tests, and dependency management
- Assume ARM-based macOS development environment
- No external service dependencies
- Clear executable demos with
mainfiles
Documentation Standards
- Front-Matter: Include YAML metadata with category, technologies (Python/Go/TypeScript/Design Patterns), estReadingMinutes: 45, exercises
- Organization: Group patterns by GoF category (Creational, Behavioral, Structural)
- SOLID Connections: Each pattern must explicitly reference relevant SOLID principle from 11.2.1
- Cross-References: Use markdown links like
[Open/Closed Principle](11-application-development/11.2.1-solid-principles.md#open-closed-principle-ocp) - Header Levels: Use H2 (
##) for navigation-visible sections, H3 (###) as default within sections - Code Snippets: Include short code examples in documentation showing pattern structure
Quiz Standards
- Format: Follow existing quizdown format from
src/quizzes/chapter-11/11.2.1/solid-principles-quiz.js - Question Types: Pattern recognition from code snippets (Python/Go/TypeScript), SOLID connections, when to use each pattern
- Question Count: 8-10 questions covering all four patterns
- Multi-Language: Include code snippets in different languages to reinforce language-agnostic concepts
- Feedback: Explain why answers are correct/incorrect and reinforce SOLID connections
🔗 Related Documentation
- Full Spec:
docs/specs/01-spec-design-patterns-section/01-spec-design-patterns-section.md - Complete Task List:
docs/specs/01-spec-design-patterns-section/01-tasks-design-patterns-section.md - Previous Tasks:
- Issue Task 1.0: Data Layer Patterns Documentation and Examples (11.2.2) #816 - Task 1.0: Data Layer Patterns
- Issue Task 2.0: Business Logic Patterns Documentation and Examples (11.2.3) #821 - Task 2.0: Business Logic Patterns
- Project Overview:
CLAUDE.md(repository root) - Style Guide:
STYLE.md(repository root)
🤖 AI Agent Instructions
Implementation Approach
- Start with Documentation: Create markdown file with proper front-matter and GoF organization structure
- Write Pattern Explanations: For each pattern, clearly explain the problem it solves, the solution, and explicit SOLID connection
- Build Examples by Pattern: Complete one pattern at a time (documentation + code + tests) before moving to next
- Emphasize SOLID Connections: Make explicit cross-references to 11.2.1 showing how patterns embody principles
- Test Multi-Language Setup: Ensure you have Python (uv), Go, and Node.js/TypeScript environments working
- Create Quiz Last: Quiz should test pattern recognition across multiple languages
- Verify All Integration: Test complete documentation with all code examples and quiz
Pattern Implementation Suggestions
Strategy Pattern (Python):
- Example: Payment processing with different payment methods (CreditCard, PayPal, Bitcoin)
- Show how adding new payment method doesn't modify existing code (OCP)
Factory Pattern (Go):
- Example: Database connection factory supporting multiple databases (PostgreSQL, MySQL, SQLite)
- Show how client depends on interface, not concrete implementations (DIP)
Observer Pattern (TypeScript):
- Example: Stock price monitoring with multiple displays (chart, table, alert)
- Show event-driven updates when stock price changes
Decorator Pattern (Python):
- Example: Coffee shop with base coffee and decorators (milk, sugar, whipped cream)
- Show how adding features doesn't modify base component (OCP)
Quality Checklist
- All code follows language-specific best practices
- Each README includes explicit SOLID principle connection
- Cross-references to 11.2.1 use correct anchor links
- All tests pass in their respective environments
- Documentation clearly organizes patterns by GoF category
- Quiz includes code snippets from multiple languages
- Pattern recognition section provides practical guidance
- Self-directed exercise is clear and actionable
Multi-Language Testing Commands
# Strategy Pattern (Python)
cd examples/ch11/classical-patterns/strategy
uv run main.py
uv run pytest
# Factory Pattern (Go)
cd examples/ch11/classical-patterns/factory
go run main.go
go test ./...
# Observer Pattern (TypeScript)
cd examples/ch11/classical-patterns/observer
npm install
npm run start
npm test
# Decorator Pattern (Python)
cd examples/ch11/classical-patterns/decorator
uv run main.py
uv run pytestSuccess Criteria
This task is complete when:
- All 17 sub-tasks are checked off
- All proof artifacts exist and are verified
- Tests pass in all four example directories (Python, Go, TypeScript)
- Each pattern README explicitly cross-references relevant SOLID principle in 11.2.1
- Quiz includes pattern recognition questions with multi-language code snippets
npm startsuccessfully renders documentation with embedded quiz- Documentation follows bootcamp conventions and clearly organizes patterns by GoF category