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 following ShippingCalculator uses an if/else chain to select between shipping strategies. Refactor it using the Strategy pattern.
// src/ShippingCalculator.ts
export class ShippingCalculator {
calculate(method: string, weightKg: number, distanceKm: number): number {
if (method === 'standard') {
return weightKg * 0.5 + distanceKm * 0.1
} else if (method === 'express') {
return weightKg * 1.2 + distanceKm * 0.3 + 5.0
} else if (method === 'overnight') {
return weightKg * 2.0 + distanceKm * 0.5 + 15.0
} else if (method === 'economy') {
return weightKg * 0.3 + distanceKm * 0.05
} else {
throw new Error(`Unknown shipping method: ${method}`)
}
}
}Produce:
IShippingStrategy.ts — the strategy interface with a calculate(weightKg: number, distanceKm: number): number method.StandardShipping.ts, ExpressShipping.ts, OvernightShipping.ts, EconomyShipping.ts.ShippingCalculator.ts — refactored to accept an IShippingStrategy and delegate to it. Must contain no arithmetic.pattern-analysis.md — describe the problem (two sentences), the win condition (one sentence), and the cost (one sentence).All TypeScript files must be valid.
clean-architecture
evals
references
design-patterns
solid-principles
testable-design