Skip to content

feat: implement Immutable pattern (Fixes #3448)#3509

Open
alex052525 wants to merge 2 commits into
iluwatar:masterfrom
alex052525:feature/immutable-pattern
Open

feat: implement Immutable pattern (Fixes #3448)#3509
alex052525 wants to merge 2 commits into
iluwatar:masterfrom
alex052525:feature/immutable-pattern

Conversation

@alex052525
Copy link
Copy Markdown

Pull Request Template

What does this PR do?

Adds the Immutable design pattern module, which was missing from the repository.

Implementation highlights

  • ImmutableUserfinal class with final fields, defensive copy via List.copyOf(),
    and wither methods (withName, withAge, withRoles) that return new instances instead of mutating state
  • App — runnable demo showing immutability and defensive copy in action
  • ImmutableUserTest — 10 JUnit 5 tests covering construction, wither behaviour,
    original-object invariance, defensive copy, and unmodifiable getter
  • etc/immutable.urm.puml — PlantUML class diagram
  • README.md — full pattern documentation following project conventions

alex052525 and others added 2 commits June 4, 2026 16:24
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>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

PR Summary

Introduces a new immutable module implementing the Immutable design pattern. Adds an ImmutableUser final class with final fields, defensive copy for lists, and wither methods (withName, withAge, withRoles). Includes a runnable App demo, JUnit 5 tests, PlantUML diagram, and README docs. Updates root pom to include the new module. Fixes #3448.

Changes

File Summary
immutable/README.md Adds documentation for the Immutable design pattern, including a complete Java example (ImmutableUser), a runnable App demo, defensive-copy semantics, and references.
immutable/etc/immutable.urm.puml PlantUML diagram for the Immutable module showing App and ImmutableUser with their relationships and wither usage.
immutable/pom.xml New Maven module for immutable with dependencies (SLF4J, Logback, JUnit 5), build plugin for executable JAR, and main class configuration.
immutable/src/main/java/com/iluwatar/immutable/App.java Demo app that constructs an ImmutableUser, demonstrates the withAge wither, and shows defensive copy behavior of roles.
immutable/src/main/java/com/iluwatar/immutable/ImmutableUser.java Defines ImmutableUser as a final class with final fields; defensively copies roles via List.copyOf; provides withName, withAge, withRoles methods returning new instances; includes toString.
immutable/src/test/java/com/iluwatar/immutable/ImmutableUserTest.java JUnit 5 tests covering constructor, withers, immutability invariants, defensive copy, and unmodifiable getRoles behavior.
pom.xml Updated root POM to declare the new immutable module in the build.

autogenerated by presubmit.ai

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

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 (2)
  • bc9f946: feat: add withName and withRoles wither methods to ImmutableUser #3448

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)

Comment thread immutable/pom.xml
Comment on lines +46 to +49
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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.

Missing Pattern Immutable

1 participant