Interactive Practice
Code Smell Challenges
Diagnose each design problem before revealing the suggested direction. Answers are saved locally.
God Class
A StudentManager class validates students, saves them to a database, sends emails, calculates grades, and prints reports.
Split responsibilities into focused collaborators such as StudentService, StudentRepository, NotificationService, GradeCalculator, and ReportFormatter.
Tight Coupling
OrderService creates a new StripePaymentGateway directly inside its constructor.
Inject a PaymentGateway abstraction so tests and alternate providers can be supplied.
Inheritance Trap
Bird has fly(), and Penguin extends Bird but throws an exception when fly() is called.
Do not model every bird as flyable. Use smaller capabilities such as a Flyable interface or composition.
Primitive Obsession
A payment method is represented everywhere by strings such as cc, paypal, and gift.
Introduce a meaningful type, enum, or strategy object so invalid states are harder to represent.
Shotgun Surgery
Adding a new discount requires editing seven unrelated files.
Centralize the variation behind a strategy, policy, or focused service.
Feature Envy
InvoicePrinter reaches through an Order object to calculate totals, taxes, and discounts.
Move behavior closer to the data it uses, or create a focused pricing service if the logic spans concepts.