-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Based on the bugs I identified in the Factory Method Pattern Java code, here's a properly formatted feature request:
Is your feature request related to a problem? Please describe.
Yes, the Factory Method Pattern documentation contains incomplete Java code examples that won't compile. The code references several undefined fields and constants (ELFARSENAL, ORCARSENAL, LOGGER, MANUFACTURED) which makes it difficult for developers to understand and implement the pattern correctly. This creates confusion for learners trying to use this as a reference implementation.
Describe the solution you'd like
I would like the Java code examples to be complete and compilable. Specifically:
- Add arsenal map declarations in both
ElfBlacksmithandOrcBlacksmithclasses:
private static final Map<WeaponType, Weapon> ELFARSENAL = new EnumMap<>(WeaponType.class);
private static final Map<WeaponType, Weapon> ORCARSENAL = new EnumMap<>(WeaponType.class);- Add LOGGER and constant declarations in the main App class:
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
private static final String MANUFACTURED = "{} manufactured {}";-
Include initialization code for the arsenal maps (or at least document that initialization is required)
-
Add null-safety checks in the
manufactureWeaponmethods to handle cases where a weapon type isn't in the arsenal -
Include basic class definitions for
WeaponandWeaponType(even if simplified) to make the example self-contained
Describe alternatives you've considered
- Add code comments indicating which parts are omitted for brevity, with references to the complete implementation
- Link to a working GitHub repository with the full, compilable code
- Add a disclaimer at the beginning stating "Note: This is pseudocode for illustration purposes"
- Create a separate "Complete Example" section with fully functional code
Additional context
The current documentation is educational material, so having non-functional code examples undermines its purpose. Developers copying this code will face immediate compilation errors, which creates friction in the learning process. Complete, working examples would significantly improve the documentation's value and reduce confusion for new learners of design patterns.