- Hands-On Design Patterns with Kotlin
- Alexey Soshin
- 74字
- 2021-06-25 20:49:28
Static Factory Method
The Static Factory Method was popularized by Joshua Bloch in his book Effective Java. To understand it better, let's look at the examples from Java standard library itself, the valueOf() methods:
Long l1 = new Long("1");
Long l2 = Long.valueOf("1");
Both the constructor and the valueOf() method receive String as input and produce Long as output.
So, why is the Static Factory Method sometimes better than a constructor?
推薦閱讀
- 大學計算機基礎(第二版)
- Web應用系統開發實踐(C#)
- UML和模式應用(原書第3版)
- Building a Game with Unity and Blender
- 編寫高質量代碼:改善Python程序的91個建議
- Getting Started with NativeScript
- RISC-V體系結構編程與實踐(第2版)
- Java Web開發就該這樣學
- Mastering HTML5 Forms
- 玩轉.NET Micro Framework移植:基于STM32F10x處理器
- Python Web自動化測試設計與實現
- Mastering Android Studio 3
- Learning Concurrency in Python
- 零基礎學編程系列(全5冊)
- Developing Java Applications with Spring and Spring Boot