refactor: apply Factory Enum Pattern for cleaner object instantiation
Closes #3301
Applied Factory Enum Pattern to CoinType enum:
- Added getInstance() method for singleton instance per coin type
- Removed dependency on CoinFactory in App.java
- Updated tests to use getInstance() directly
PR Summary
Closes #3301. Applied the Factory Enum Pattern to the CoinType enum by introducing a per-type singleton via getInstance(); removed CoinFactory dependency from App.java; updated tests to instantiate coins via CoinType.getInstance() and added tests to verify singleton behavior.
Changes
| File | Summary |
|---|---|
factory/src/main/java/com/iluwatar/factory/App.java |
Replaced CoinFactory usage with per-type singleton access: CoinType.COPPER.getInstance() and CoinType.GOLD.getInstance() in main; preserves coin description logs. |
factory/src/main/java/com/iluwatar/factory/CoinType.java |
Introduced lazy singleton per coin type via getInstance(); added private instance field and getter; removed CoinFactory dependency in favor of enum-provided instances. |
factory/src/test/java/com/iluwatar/factory/CoinFactoryTest.java |
Updated tests to use CoinType.getInstance(); added tests for copper instance and singleton equality. |
autogenerated by presubmit.ai
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 83.28%. Comparing base (fcdf639) to head (569afc8).
Additional details and impacted files
@@ Coverage Diff @@
## master #3523 +/- ##
============================================
- Coverage 83.28% 83.28% -0.01%
- Complexity 4023 4024 +1
============================================
Files 1060 1060
Lines 14246 14249 +3
Branches 686 686
============================================
+ Hits 11865 11867 +2
- Misses 2094 2095 +1
Partials 287 287
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.