Programming Homework Help
Walden University Package Planning and Abstract Factory Pattern Project
I am trying to learn how to create an abstract factory from an existing code and then refactor the existing code. Enclosed are a couple of screen shots from the Java file. I believe the Abstract Factory would be inserted at line 47.
Plan class is a tightly coupled factory. The part of the constructor that chooses absorbents and special cautions based on spill type can be modified to use the Abstract Factory pattern to get the correct absorbent and cautions once the spill type is known, without any further logic. This decreases the coupling by removing the knowledge of absorbent and caution details and moving it into subclasses specifically designed for that information.
The Plan constructor method creates the correct plan for a situation based on input from a responder about an emergency chemical spill. Instead of having the Plan make decisions and update state variables in both the absorbents and the cautions objects, I am trying to encapsulate this logic as an abstract factory. The old conditional can then be refactored into a compact choice of which concrete factory to use, based on the spill material.