Skip to content
Ameen Abozaid
Planned lessonJNR-013-L04

Repositories: data access behind an interface

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

hide storage behind an interface.

Planned topics

  • The repository interface says what you can store and find, not how.
  • In this phase the implementation is in memory (a Map); JNR-P4 swaps in a database.
  • The service depends on the interface, so it does not change when storage does.
  • @Repository marks the implementation.
Draft outline details

Demonstration

java
interface ProductRepository {
    Optional<Product> findById(long id);
    List<Product> findAll();
}

Check your understanding

Why return Optional?

Show answer

A product may not exist; the type says so.

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.