Skip to content
Ameen Abozaid
Planned lessonJNR-009-L01

Wiring by hand: the problem

  • Lesson 1 of 8
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

see why creating collaborators inside a class hurts.

Planned topics

  • If OrderService does new StripePayment() itself, it is glued to that class.
  • You cannot swap the payment provider or test the service with a fake.
  • A dependency is any object a class needs to do its work.
  • Hard-wiring spreads: change one constructor and many places break.
Draft outline details

Demonstration

java
class OrderService {
    private final PaymentProvider payment = new StripePayment(); // glued
}

Check your understanding

Why is this hard to test?

Show answer

The service always uses the real provider; you cannot give it a fake.

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.

Continue to next lesson

Type to search levels, phases, modules and lessons.