,WGU D780 Task 1 - Design Patterns & Refactoring -
PRACTICE EXEMPLAR
Complete Design Patterns and Python Code
Refactoring Exemplar with Detailed Explanations
and Tested Code | 2026/2027 Updated
Part 1: Architectural Analysis & Refactoring
Strategy
1. Legacy Monolith Codebase Issues
In a typical legacy retail or order-processing system
(e.g., the legacy codebase targeted in WGU D780
Task 1), a single monolithic class often manages
product pricing, discount logic, payment processing,
notification dispatch, and receipt generation.
Identified Anti-Patterns & Violations:
• Single Responsibility Principle (SRP)
Violation: The main order manager class
handles business calculation, external API
payment calls, email notification formatting, and
file I/O operations simultaneously.
• Open/Closed Principle (OCP) Violation:
Adding a new payment processor (e.g., Apple
Pay, PayPal) or a seasonal discount strategy
requires directly modifying if-elif-else
, branches inside core order processing methods,
introducing regression risks.
• Tight Coupling: Core business logic directly
instantiates concrete third-party services (e.g.,
SMTPClient, StripeAPI), making isolated
unit testing impossible without live network
connections.
2. Design Pattern Selection & Architectural
Strategy
To refactor this tightly coupled monolith into a clean,
extensible, and maintainable architecture, three core
GoF design patterns are introduced:
+----------------------------------
-----------------------------------
--+
| Order
Context
|
+----------------------------------
-----------------------------------
--+
|
|
v
v
, +-----------------------+ +--
---------------------+
| Strategy Pattern | |
Factory Pattern |
| (Discount Logic) | |
(Payment Processors) |
+-----------------------+ +--
---------------------+
- PercentageDiscount -
CreditCardProcessor
- FixedAmountDiscount -
PayPalProcessor
- BlackFridayDiscount -
CryptoProcessor
|
v
+----------------------------------
---------------------+
| Observer Pattern
|
| (Decoupled Event
Notifications) |
+----------------------------------
---------------------+
- EmailNotificationObserver
- SMSNotificationObserver
- InventoryAuditObserver
PRACTICE EXEMPLAR
Complete Design Patterns and Python Code
Refactoring Exemplar with Detailed Explanations
and Tested Code | 2026/2027 Updated
Part 1: Architectural Analysis & Refactoring
Strategy
1. Legacy Monolith Codebase Issues
In a typical legacy retail or order-processing system
(e.g., the legacy codebase targeted in WGU D780
Task 1), a single monolithic class often manages
product pricing, discount logic, payment processing,
notification dispatch, and receipt generation.
Identified Anti-Patterns & Violations:
• Single Responsibility Principle (SRP)
Violation: The main order manager class
handles business calculation, external API
payment calls, email notification formatting, and
file I/O operations simultaneously.
• Open/Closed Principle (OCP) Violation:
Adding a new payment processor (e.g., Apple
Pay, PayPal) or a seasonal discount strategy
requires directly modifying if-elif-else
, branches inside core order processing methods,
introducing regression risks.
• Tight Coupling: Core business logic directly
instantiates concrete third-party services (e.g.,
SMTPClient, StripeAPI), making isolated
unit testing impossible without live network
connections.
2. Design Pattern Selection & Architectural
Strategy
To refactor this tightly coupled monolith into a clean,
extensible, and maintainable architecture, three core
GoF design patterns are introduced:
+----------------------------------
-----------------------------------
--+
| Order
Context
|
+----------------------------------
-----------------------------------
--+
|
|
v
v
, +-----------------------+ +--
---------------------+
| Strategy Pattern | |
Factory Pattern |
| (Discount Logic) | |
(Payment Processors) |
+-----------------------+ +--
---------------------+
- PercentageDiscount -
CreditCardProcessor
- FixedAmountDiscount -
PayPalProcessor
- BlackFridayDiscount -
CryptoProcessor
|
v
+----------------------------------
---------------------+
| Observer Pattern
|
| (Decoupled Event
Notifications) |
+----------------------------------
---------------------+
- EmailNotificationObserver
- SMSNotificationObserver
- InventoryAuditObserver