Skip to content

feat: add Immutable Object design pattern (#3448)#3485

Open
prashantpiyush1111 wants to merge 4 commits into
iluwatar:masterfrom
prashantpiyush1111:master
Open

feat: add Immutable Object design pattern (#3448)#3485
prashantpiyush1111 wants to merge 4 commits into
iluwatar:masterfrom
prashantpiyush1111:master

Conversation

@prashantpiyush1111
Copy link
Copy Markdown

What does this PR do?

Fixes #3448

Added Immutable Object design pattern with:

  • ImmutableObject.java with final fields
  • README.md with explanation and usage
  • pom.xml configuration

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 27, 2026

PR Summary

Introduces the Immutable Object design pattern with a new ImmutableObject class and accompanying tests and documentation. The object is fully immutable, with final fields and null safety, and includes proper equals/hashCode implementations. A dedicated Maven module immutable is added with JUnit 5 tests and a README explaining usage.

Changes

File Summary
immutable/README.md Adds a README describing the Immutable Object pattern, its intent, usage, and example scenario.
immutable/pom.xml Introduces a Maven module immutable with JUnit dependency for tests.
immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java Implements an immutable object with final fields name, age, email; validates inputs; provides accessors; overrides toString, equals, and hashCode.
immutable/src/test/java/com/iluwatar/immutable/ImmutableObjectTest.java Adds unit tests verifying object creation, string representation, immutability via distinct instances, equality semantics, and null-safety.

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 (1)
  • 0fd6085: feat: add Immutable Object design pattern (#3448)
Files Processed (3)
  • immutable/README.md (1 hunk)
  • immutable/pom.xml (1 hunk)
  • immutable/src/main/java/ImmutableObject.java (1 hunk)
Actionable Comments (1)
  • immutable/src/main/java/ImmutableObject.java [7-7]

    possible bug: "Package path mismatch"

Skipped Comments (2)
  • immutable/src/main/java/ImmutableObject.java [13-20]

    best_practice: "Null safety in constructor"

  • immutable/README.md [1-19]

    readability: "Documentation accuracy"

* Immutable Object pattern.
* Once created, the object state cannot be changed.
*/
public final class ImmutableObject {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The file declares a package path that does not align with typical Maven source layout. Maven/Java projects expect directory structure immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java for package com.iluwatar.immutable. Move the file to the proper path or adjust the package declaration to reflect the directory structure.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in commit 7cdf02b.
File moved to correct path:
immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java

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.

LGTM!

Review Summary

Commits Considered (1)
  • 7cdf02b: fix: move ImmutableObject to correct package path
Files Processed (1)
  • immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java [1-34]

    best practice: "Defensive nullability for value object"

  • immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java [1-34]

    enhancement: "Add value-based equality"

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.

LGTM!

Review Summary

Commits Considered (1)
  • 1c41504: test: add ImmutableObjectTest for coverage
Files Processed (1)
  • immutable/src/test/java/com/iluwatar/immutable/ImmutableObjectTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • immutable/src/test/java/com/iluwatar/immutable/ImmutableObjectTest.java [27-35]

    best practice: "Immutability test is weak"

  • immutable/src/test/java/com/iluwatar/immutable/ImmutableObjectTest.java [19-24]

    readability: "Fragile toString assertion"

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.

LGTM!

Review Summary

Commits Considered (1)
  • 26287aa: refactor: add equals, hashCode, null safety and tests
Files Processed (2)
  • immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java (1 hunk)
  • immutable/src/test/java/com/iluwatar/immutable/ImmutableObjectTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java [14-21]

    best_practice: "Invariant: age validity"

  • immutable/src/test/java/com/iluwatar/immutable/ImmutableObjectTest.java [27-34]

    readability: "Test immutability assertion is weak"

Copy link
Copy Markdown
Author

@prashantpiyush1111 prashantpiyush1111 left a comment

Choose a reason for hiding this comment

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

Fixed in commit 7cdf02b.
File moved to correct path:
immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java

* Immutable Object pattern.
* Once created, the object state cannot be changed.
*/
public final class ImmutableObject {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in commit 7cdf02b.
File moved to correct path:
immutable/src/main/java/com/iluwatar/immutable/ImmutableObject.java

@sonarqubecloud
Copy link
Copy Markdown

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