Strategic architecture, tactical design, and testable code principles (SOLID, Clean Architecture, Design Patterns, Testable Design)
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
The OrderProcessor class directly instantiates a low-level EmailNotifier. Refactor to satisfy the Dependency Inversion Principle.
// src/notifications/EmailNotifier.ts
export class EmailNotifier {
async notify(recipient: string, subject: string, body: string): Promise<void> {
// Sends email via SMTP
console.log(`Email to ${recipient}: [${subject}] ${body}`)
}
}
// src/OrderProcessor.ts
import { EmailNotifier } from './notifications/EmailNotifier'
export class OrderProcessor {
private notifier = new EmailNotifier()
async process(orderId: string, userEmail: string): Promise<void> {
// ... order processing logic ...
await this.notifier.notify(
userEmail,
'Order Confirmed',
`Your order ${orderId} has been confirmed.`
)
}
}Produce:
INotifier.ts — an interface that EmailNotifier will implement. The interface must be defined in the application/domain layer, not in the infrastructure layer.EmailNotifier.ts — updated to implement INotifier.OrderProcessor.ts — refactored to depend on INotifier via constructor injection. It must not import EmailNotifier.dip-analysis.md — explain the DIP violation and the direction of the dependency before and after the refactor (one short paragraph each).clean-architecture
evals
references
design-patterns
solid-principles
testable-design