Repositories: data access behind an interface
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.
@Repositorymarks the implementation.
Draft outline details
Demonstration
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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.