- Mastering Objectoriented Python
- Steven F. Lott
- 52字
- 2021-11-12 16:25:00
Tip
Factory functions encapsulate complexity
There's a trade-off that occurs between sophisticated __init__()
methods and factory functions. It's often better to stick with more direct but less programmer-friendly __init__()
methods and push the complexity into factory functions. A factory function works well if you wish to wrap and encapsulate the construction complexities.