feat: implement Immutable pattern (Fixes #3448)#3509
Conversation
Add immutable/ module with ImmutableUser (final class, defensive copy, withAge wither method), App demo, JUnit 5 tests, PlantUML diagram, and README following project conventions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…atar#3448 Every field now has a corresponding wither for consistency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PR SummaryIntroduces a new immutable module implementing the Immutable design pattern. Adds an Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (2)
Every field now has a corresponding wither for consistency.
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
Add immutable/ module with ImmutableUser (final class, defensive copy,
withAge wither method), App demo, JUnit 5 tests, PlantUML diagram, and
README following project conventions.
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
Files Processed (7)
- immutable/README.md (1 hunk)
- immutable/etc/immutable.urm.puml (1 hunk)
- immutable/pom.xml (1 hunk)
- immutable/src/main/java/com/iluwatar/immutable/App.java (1 hunk)
- immutable/src/main/java/com/iluwatar/immutable/ImmutableUser.java (1 hunk)
- immutable/src/test/java/com/iluwatar/immutable/ImmutableUserTest.java (1 hunk)
- pom.xml (1 hunk)
Actionable Comments (1)
-
immutable/pom.xml [46-49]
maintainability: "Add JUnit Jupiter API as a test dependency"
Skipped Comments (0)
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> |
There was a problem hiding this comment.
JUnit Jupiter API dependency is missing. Tests in this module rely on org.junit.jupiter.api APIs (e.g., assertThrows, @test). Add junit-jupiter-api as a test dependency to ensure the test compilation succeeds alongside junit-jupiter-engine.
Pull Request Template
What does this PR do?
Adds the Immutable design pattern module, which was missing from the repository.
Implementation highlights
ImmutableUser—final classwithfinalfields, defensive copy viaList.copyOf(),and wither methods (
withName,withAge,withRoles) that return new instances instead of mutating stateApp— runnable demo showing immutability and defensive copy in actionImmutableUserTest— 10 JUnit 5 tests covering construction, wither behaviour,original-object invariance, defensive copy, and unmodifiable getter
etc/immutable.urm.puml— PlantUML class diagramREADME.md— full pattern documentation following project conventions