Skip to content
Ameen Abozaid
Planned lessonJNR-009-L02

Inversion of control

  • Lesson 2 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

explain IoC and dependency injection without Spring.

Planned topics

  • Inversion of control (IoC): someone else creates and connects your objects; you stop doing it.
  • Dependency injection (DI) is the common form: dependencies are handed in from outside.
  • The class declares what it needs; it does not decide which implementation.
  • Depend on an interface (PaymentProvider), not a concrete class.
Draft outline details

Demonstration

java
class OrderService {
    private final PaymentProvider payment;
    OrderService(PaymentProvider payment) { this.payment = payment; }
}
var service = new OrderService(new StripePayment()); // main() acts as the "container"

Check your understanding

Who decides which implementation is used now?

Show answer

The caller or container, not the service.

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.