- Hands-On Design Patterns with Kotlin
- Alexey Soshin
- 81字
- 2021-06-25 20:49:28
Advantages of the Static Factory Method
Here are some of the advantages of a Static Factory Method over constructors:
- It provides a better name for the constructor, what it expects, and, sometimes, what it produces.
- We usually don't expect exceptions from a constructor. Exceptions from a regular method, on the other hand, are totally valid.
- Speaking of expectations, we expect the constructor to be fast.
But those are more psychological advantages. There are also some technological advantages to this approach.
推薦閱讀