DEV Community

Discussion on: How to avoid the Factory pattern in C#

Collapse
 
shimmer profile image
Brian Berns • Edited

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.