What is your threshold to use factory instead of a constructor to create an object?
- You always use factory.
- You use factories only if you have invariant checks other than checking for nulls.
- You always use constructors
- You rarely use factories... what are those cases??
pros and cons
Update: I am applying factory pattern from Domain Driven Design in my project. And one of the reason behind creating factories is to reduce noise in the domain model.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…