Skip to content

feat: add Layer Supertype pattern (#1302) - #3632

Open
tiennm99 wants to merge 2 commits into
iluwatar:masterfrom
tiennm99:feat/layer_supertype_pattern
Open

tiennm99 wants to merge 2 commits into
iluwatar:masterfrom
tiennm99:feat/layer_supertype_pattern

Conversation

@tiennm99

Copy link
Copy Markdown
Contributor

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

  • Domain-layer supertype DomainObject: owns the id, isNew() and a one-time assignId(). equals() and hashCode() are final and id-based, and the hash code does not change when the id is assigned, so an object stays in a HashSet after it is saved. Customer and Product hold only their own fields.
  • Data-access-layer supertype Repository<T extends DomainObject>: in-memory storage with its own id sequence, save, findById, findAll, delete and a protected findWhere(Predicate). It rejects objects that carry an id from another repository. CustomerRepository and ProductRepository add only their own queries.
  • App shows the inherited operations, the layer-specific queries and the id-based equality.
  • README following the pattern template, class diagram (etc/layer-supertype.urm.puml and .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:check passes.

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.
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

Adds 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

File Summary
layer-supertype/README.md Documentation and example describing the Layer Supertype pattern, including domain and repository supertypes, usage, tests, and diagrams.
layer-supertype/etc/layer-supertype.urm.png New binary UML diagram image asset illustrating the Layer Supertype example.
layer-supertype/etc/layer-supertype.urm.puml PlantUML model describing domain objects, repositories and their relationships in the Layer Supertype example.
layer-supertype/pom.xml Module POM configuring dependencies, build plugin, and main class for the Layer Supertype module.
layer-supertype/src/main/java/com/iluwatar/layersupertype/App.java Demo application showing inheritance and usage of the layer supertypes (domain and repository layers).
layer-supertype/src/main/java/com/iluwatar/layersupertype/Customer.java Domain object Customer extending DomainObject with name and email fields.
layer-supertype/src/main/java/com/iluwatar/layersupertype/CustomerRepository.java Repository for Customer, extends Repository<Customer>, includes findByEmail method.
layer-supertype/src/main/java/com/iluwatar/layersupertype/DomainObject.java Domain layer supertype containing id, isNew(), assignId(long), and final equals/hashCode based on type and id.
layer-supertype/src/main/java/com/iluwatar/layersupertype/Product.java Domain object Product extending DomainObject with name and price fields.
layer-supertype/src/main/java/com/iluwatar/layersupertype/ProductRepository.java Repository for Product, extends Repository<Product>, includes findCheaperThan method.
layer-supertype/src/main/java/com/iluwatar/layersupertype/Repository.java Layer data-access supertype with in-memory storage, id generation, and shared CRUD methods; enforces cross-repo safety; provides findWhere.
layer-supertype/src/test/java/com/iluwatar/layersupertype/AppTest.java Test ensuring App.main runs without exceptions.
layer-supertype/src/test/java/com/iluwatar/layersupertype/DomainObjectTest.java Tests for DomainObject lifecycle, equality and hashCode behavior.
layer-supertype/src/test/java/com/iluwatar/layersupertype/RepositoryTest.java Tests for repository behavior: IDs, save/update, find, delete, and lookups per type.
pom.xml Parent POM updated to include the layer-supertype module.

autogenerated by presubmit.ai

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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)"

Comment on lines +54 to +59
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")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.43750% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.09%. Comparing base (4cabb20) to head (7b37746).

Files with missing lines Patch % Lines
...src/main/java/com/iluwatar/layersupertype/App.java 96.15% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant