A minimal demonstration of a repository abstraction backed by an in-memory collection.
The repository interface hides the data source behind a contract.
The caller works against OwnerRepository and has no knowledge of how or where data is stored.
FakeOwnerRepository simulates a database using a LinkedHashMap — useful for prototyping and testing without a real persistence layer.
All code is in a single file: FakeRepositorySampleApplication.java
FakeRepositorySampleApplication.java
│
├── Owner # Entity — record with id and name
├── OwnerRepository # Repository interface — findAll()
├── FakeOwnerRepository # In-memory implementation using LinkedHashMap
└── FakeRepositorySampleApplication # Entry point + demo()
Interface as contract. The calling code works against OwnerRepository — not the implementation. Swapping the backing store requires no changes to the caller.
LinkedHashMap preserves insertion order. Records are returned in the order they were added — predictable and consistent across calls.
List.copyOf protects the internal state. The repository returns an unmodifiable copy — the caller cannot mutate the underlying collection.
Owner[id=1, name=jack1]
Owner[id=2, name=jack2]
Owner[id=3, name=jack3]
Owner[id=4, name=jack4]
Owner[id=5, name=jack5]
./mvnw spring-boot:run- Previous: pattern-dao-sample
- Next: in-memory-repository-sorting-sample