Internal `CreateProcessFactory` should be refactored to a non-static and DI'ble approach
sbuerk opened this issue · comments
Stefan Bürk commented
Basically, there are different ways to implement class
factories. Using a final
class with a static method
without a interface on the factory class or the class
to be created by the factory is considerable bad and
prevents proper exchanging things.
A industry wide approach for providing good and exchangable
factories is following way:
- Build upon a factory class interface, ex.
MyFactoryInterface
- Providing a abstract factory class implementing the interface
and the default behaviour, ex.AbstractFactory
- Provide a slim class implementation based on the
AbstractFactory
,
MyFactory extends AbstractFactory
- Add a DI configuration to retrieve the
MyFactory
based on the
MyFactoryInterface
. - Use DI in code places to retrieve the factory based on the interface
and operate with this.
Therefore, the implementation should change - even staying internal.
That helps more experienced developers but not making it a API for now.