書名: Hands-On Design Patterns with Kotlin作者名: Alexey Soshin本章字?jǐn)?shù): 81字更新時(shí)間: 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.
推薦閱讀
- 算法零基礎(chǔ)一本通(Python版)
- C語言程序設(shè)計(jì)(第2版)
- Java Web開發(fā)技術(shù)教程
- 數(shù)據(jù)結(jié)構(gòu)(C語言)
- Rust Essentials(Second Edition)
- C語言程序設(shè)計(jì)學(xué)習(xí)指導(dǎo)與習(xí)題解答
- Visual Basic程序設(shè)計(jì)
- jQuery炫酷應(yīng)用實(shí)例集錦
- Machine Learning in Java
- Raspberry Pi Robotic Projects(Third Edition)
- 區(qū)塊鏈架構(gòu)之美:從比特幣、以太坊、超級(jí)賬本看區(qū)塊鏈架構(gòu)設(shè)計(jì)
- Selenium WebDriver Practical Guide
- SAS編程演義
- Ionic3與CodePush初探:支持跨平臺(tái)與熱更新的App開發(fā)技術(shù)
- Java EE 7 Development with WildFly