Concrete Dependency Injection (ARCH4199)
Esta página aún no está disponible en tu idioma.
Key java.quality.concrete-dependency · Severity info · Category quality
Constructor dependencies typed as concrete classes violate the dependency inversion principle; they pin the implementation and make test doubles harder to use. Depend on an interface.
Incorrect
Section titled “Incorrect”@Serviceclass CheckoutService { private final StripePaymentGateway gateway; CheckoutService(StripePaymentGateway gateway) { this.gateway = gateway; }}Correct
Section titled “Correct”@Serviceclass CheckoutService { private final PaymentGateway gateway; CheckoutService(PaymentGateway gateway) { this.gateway = gateway; }}Type the dependency as an interface/abstraction rather than a concrete class.