Skip to content

feat: add factory enum #3300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

huunghia98er
Copy link

Pull Request Template

What does this PR do?

  1. Refactors the existing Factory Pattern implementation to use Factory Enum Pattern.
  • Moves object creation logic into enum (FileProcessorType)

  • Removes the need for a separate factory class

  1. Applies singleton via InstanceHolder for each processor

Why is this change necessary?

  • Simplifies the codebase by eliminating boilerplate factory classes

  • Improves readability and maintainability

  • Leverages type-safe enum-based instantiation

  • Aligns with modern Java practices (e.g. Enum Singleton)

Copy link

github-actions bot commented Jul 8, 2025

PR Summary

This PR refactors the Factory Pattern implementation to use the Factory Enum Pattern. It moves object creation logic into an enum (FileProcessorType), removes the need for a separate factory class, and applies a singleton pattern via InstanceHolder for each processor. This simplifies the codebase, improves readability and maintainability, and leverages type-safe enum-based instantiation.

Changes

File Summary
factory-enum/README.md This file provides a comprehensive guide to the Factory Enum Pattern in Java. It includes a real-world analogy, a programmatic example using FileProcessor, and a discussion of when to use this pattern, its benefits, and trade-offs.
factory-enum/etc/factory-sequence-diagram.png New file: Sequence diagram for the Factory Enum pattern.
factory-enum/etc/factory.urm.png New file: UML diagram for the Factory Enum pattern.
factory-enum/etc/factory.urm.puml New file: PlantUML script for generating the UML diagram of the Factory Enum pattern.
factory-enum/pom.xml This file configures the Maven project, including dependencies for logging (SLF4j, Logback) and testing (JUnit Jupiter).
factory-enum/src/main/java/com/iluwatar/factory/App.java This Java class demonstrates the usage of the FileProcessorType enum to create and use instances of FileProcessor implementations.
factory-enum/src/main/java/com/iluwatar/factory/ExcelProcessor.java This class implements the FileProcessor interface for processing Excel files and uses the singleton pattern.
factory-enum/src/main/java/com/iluwatar/factory/FileProcessor.java This interface defines the contract for file processors, specifying a method to get a description.
factory-enum/src/main/java/com/iluwatar/factory/FileProcessorType.java This enum manages the creation and access of different file processor instances using the Factory Enum pattern.
factory-enum/src/main/java/com/iluwatar/factory/PDFProcessor.java This class implements the FileProcessor interface for processing PDF files and uses the singleton pattern.
factory-enum/src/test/java/com/iluwatar/factory/AppTest.java This test class verifies that the main application runs without exceptions.
factory-enum/src/test/java/com/iluwatar/factory/FileProcessorTest.java This test class contains unit tests for the FileProcessorType enum and its associated classes.
pom.xml The factory-enum module was added to the list of modules in the parent pom.xml file.

autogenerated by presubmit.ai

Copy link

@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)
Files Processed (13)
  • factory-enum/README.md (1 hunk)
  • factory-enum/etc/factory-sequence-diagram.png (0 hunks)
  • factory-enum/etc/factory.urm.png (0 hunks)
  • factory-enum/etc/factory.urm.puml (1 hunk)
  • factory-enum/pom.xml (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/App.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/ExcelProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessorType.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/PDFProcessor.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/AppTest.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/FileProcessorTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

@huunghia98er huunghia98er force-pushed the mosdvc/add-factory-enum branch from a1b64c2 to d9d283d Compare July 8, 2025 03:31
Copy link

@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)
Files Processed (13)
  • factory-enum/README.md (1 hunk)
  • factory-enum/etc/factory-sequence-diagram.png (0 hunks)
  • factory-enum/etc/factory.urm.png (0 hunks)
  • factory-enum/etc/factory.urm.puml (1 hunk)
  • factory-enum/pom.xml (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/App.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/ExcelProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessorType.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/PDFProcessor.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/AppTest.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/FileProcessorTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

@huunghia98er huunghia98er force-pushed the mosdvc/add-factory-enum branch from d9d283d to 4359e00 Compare July 8, 2025 03:41
Copy link

@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)
Files Processed (13)
  • factory-enum/README.md (1 hunk)
  • factory-enum/etc/factory-sequence-diagram.png (0 hunks)
  • factory-enum/etc/factory.urm.png (0 hunks)
  • factory-enum/etc/factory.urm.puml (1 hunk)
  • factory-enum/pom.xml (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/App.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/ExcelProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessorType.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/PDFProcessor.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/AppTest.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/FileProcessorTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

@huunghia98er huunghia98er force-pushed the mosdvc/add-factory-enum branch from 4359e00 to bcabb8f Compare July 8, 2025 04:00
Copy link

@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)
Files Processed (13)
  • factory-enum/README.md (1 hunk)
  • factory-enum/etc/factory-sequence-diagram.png (0 hunks)
  • factory-enum/etc/factory.urm.png (0 hunks)
  • factory-enum/etc/factory.urm.puml (1 hunk)
  • factory-enum/pom.xml (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/App.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/ExcelProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessor.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/FileProcessorType.java (1 hunk)
  • factory-enum/src/main/java/com/iluwatar/factory/PDFProcessor.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/AppTest.java (1 hunk)
  • factory-enum/src/test/java/com/iluwatar/factory/FileProcessorTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

Copy link

sonarqubecloud bot commented Jul 8, 2025

@letdtcode
Copy link

I think you should create new issue for this one

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.

2 participants