Skip to content
Ameen Abozaid
In reviewJNR-004-L07

Demo: dependency inversion for a payment provider

  • Lesson 7 of 7
  • 10 min read
  • Junior
On This Lesson 3 topics

The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.

In this lesson

inject a payment provider through an interface. Prepares JNR-004-LAB1.

Draft outline details

Step by step

  1. Show CheckoutService calling new StripeClient() directly; tests need the network.
  2. Extract the PaymentProvider interface.
  3. Inject it through the constructor.
  4. Planned mistake: the interface exposes Stripe-specific types, so the core still depends on Stripe. Fix: use Shop's own types (Money, Receipt) in the interface.
  5. Write a fake provider for tests; run them without a network.
  6. Add a second provider without touching CheckoutService.

Check your understanding

Where should the interface live?

Show answer

In the core, not in the provider's code.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.