Skip to content
loading...

re: How to avoid the Factory pattern in C# VIEW POST

FULL DISCUSSION
 

I feel some anti-pattern issues:

  • It accepts any function that returns IAnimal, not just factories. This can be risky in the long run.
  • It decentralizes factories. This will eventually end up writing plenty of duplicate code, and possible local or private functions that do similar but slightly different initializations, probably when you need more customization.

You can see where it is going.

 

It accepts any function that returns IAnimal, not just factories. This can be risky in the long run.

This is no different from the factory pattern, which accepts any object that implements IAnimalFactory. I don't think there's any risk involved.

This will eventually end up writing plenty of duplicate code

I don't follow you. How does the factory pattern (or my functional version of it) lead to duplicate code? An example might help.

code of conduct - report abuse