Repository navigation
Conversation
Add a standalone layer-supertype module. DomainObject is the domain layer supertype that owns id, persisted state and id-based equality; Repository is the data access layer supertype that owns id generation and the save, find and delete operations. Customer, Product and their repositories add only their own data and queries.
PR SummaryAdds a standalone layer-supertype module implementing the Layer Supertype pattern with DomainObject and Repository supertypes, concrete Customer/Product and their repositories, an App demonstration, tests, and documentation (README, UML diagrams). Refactoring existing modules onto a supertype is deferred to a separate PR. Verification via mvnw -pl layer-supertype clean verify license:check is supported. Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
Add a standalone layer-supertype module. DomainObject is the domain
layer supertype that owns id, persisted state and id-based equality;
Repository is the data access layer supertype that owns id generation
and the save, find and delete operations. Customer, Product and their
repositories add only their own data and queries.
Files Processed (15)
- layer-supertype/README.md (1 hunk)
- layer-supertype/etc/layer-supertype.urm.png (0 hunks)
- layer-supertype/etc/layer-supertype.urm.puml (1 hunk)
- layer-supertype/pom.xml (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/App.java (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/Customer.java (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/CustomerRepository.java (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/DomainObject.java (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/Product.java (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/ProductRepository.java (1 hunk)
- layer-supertype/src/main/java/com/iluwatar/layersupertype/Repository.java (1 hunk)
- layer-supertype/src/test/java/com/iluwatar/layersupertype/AppTest.java (1 hunk)
- layer-supertype/src/test/java/com/iluwatar/layersupertype/DomainObjectTest.java (1 hunk)
- layer-supertype/src/test/java/com/iluwatar/layersupertype/RepositoryTest.java (1 hunk)
- pom.xml (1 hunk)
Actionable Comments (1)
-
layer-supertype/src/main/java/com/iluwatar/layersupertype/App.java [54-59]
best_practice: "Logging field name mismatch with Lombok annotation"
Skipped Comments (1)
-
layer-supertype/src/main/java/com/iluwatar/layersupertype/Repository.java [100-102]
maintainability: "Potential Java version compatibility issue (toList)"
| LOGGER.info("Customers: {}", customers.findAll()); | ||
| LOGGER.info("Products: {}", products.findAll()); | ||
|
|
||
| LOGGER.info( | ||
| "Customer with email bob@example.com: {}", customers.findByEmail("BOB@example.com")); | ||
| LOGGER.info("Products cheaper than 50: {}", products.findCheaperThan(new BigDecimal("50"))); |
There was a problem hiding this comment.
Logging field name mismatch with Lombok annotation. Lombok's @slf4j generates a field named 'log' (not 'LOGGER'). The current code references LOGGER, which will not be found at compile time. Either:
- change the references to use 'log', or
- switch to a Lombok annotation that generates a field named LOGGER (e.g., @log if appropriate to your logging setup).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3632 +/- ##
============================================
+ Coverage 84.06% 84.09% +0.02%
- Complexity 4353 4382 +29
============================================
Files 1133 1140 +7
Lines 15400 15464 +64
Branches 739 742 +3
============================================
+ Hits 12946 13004 +58
- Misses 2158 2161 +3
- Partials 296 299 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
- 7b37746: test: cover equals against null in Layer Supertype
Files Processed (1)
- layer-supertype/src/test/java/com/iluwatar/layersupertype/DomainObjectTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
-
layer-supertype/src/test/java/com/iluwatar/layersupertype/DomainObjectTest.java [46-53]
enhancement: "Enforce one-time ID assignment in test"
-
layer-supertype/src/test/java/com/iluwatar/layersupertype/DomainObjectTest.java [93-101]
enhancement: "HashCode stability after ID assignment"
Related to #1302.
Adds the Layer Supertype pattern: one abstract base class per layer that holds the behaviour every class in that layer shares.
What is included
DomainObject: owns the id,isNew()and a one-timeassignId().equals()andhashCode()are final and id-based, and the hash code does not change when the id is assigned, so an object stays in aHashSetafter it is saved.CustomerandProducthold only their own fields.Repository<T extends DomainObject>: in-memory storage with its own id sequence,save,findById,findAll,deleteand a protectedfindWhere(Predicate). It rejects objects that carry an id from another repository.CustomerRepositoryandProductRepositoryadd only their own queries.Appshows the inherited operations, the layer-specific queries and the id-based equality.etc/layer-supertype.urm.pumland.png), and 16 unit tests.Scope
The issue's second criterion asks to refactor existing modules onto a supertype. This PR leaves that out on purpose to keep the change atomic: it adds a standalone module and touches no other module. The refactor can follow in a separate PR.
Verification
./mvnw -pl layer-supertype clean verify license:checkpasses.