Wiring by hand: the problem
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
OrderServicedoesnew 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
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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.