33
A
回答
11
30
我一直認爲構造函數注入到最終字段是最佳實踐。它通過使類的正式依賴顯式化,使可變狀態最小化並使類更易於理解。
public class MyClass {
private final MyDependency dependency;
@Inject
public MyClass(MyDependency dependency) {
this.dependency = dependency;
}
}
相關問題
- 1. Rails的最佳做法/命名模式
- 2. 模式/最佳做法參數WebService
- 3. WCF和NoSql最佳做法
- 4. 制定業務層安全的方法。最佳做法/最佳模式
- 5. 遵循視圖模型模式的最佳做法
- 6. RabbitMQ - 最佳做法
- 7. 最佳做法response.getOutputStream
- 8. estimatedHeightForRowAtIndexPath最佳做法
- 9. 最佳做法applicationDidEnterBackground
- 10. 最佳做法UIScrollView
- 11. ActionListener最佳做法
- 12. CLLocationManager最佳做法
- 13. 這是一個Guice反模式嗎?
- 14. Python模塊的最佳做法
- 15. 模型視圖的最佳做法
- 16. 播放2.0模型的最佳做法
- 17. 反應行動回撥做轉換最佳做法
- 18. 反應本地動畫示例違反最佳做法?
- 19. JavaMail編程最佳或最佳做法
- 20. HTML5視頻格式最佳做法
- 21. 樣式選擇選項最佳做法
- 22. DI,Guice和策略模式
- 23. 最佳做法/上網和互動式移動(Android)遊戲的最佳服務
- 24. 最佳做法代表團&&數據源模式
- 25. 登錄表單模式窗口的最佳做法
- 26. 顯示MVP模式驗證錯誤的最佳做法
- 27. 存儲分隔文本文件模式的最佳做法
- 28. 在SQL 2005中使用模式的最佳做法?
- 29. dynamic_cast和多態性的最佳做法
- 30. Nginx和runit ....什麼是最佳做法
我鼓勵任何有興趣參與這個問題的人去看看[Guice docs](http://stackoverflow.com/documentation/guice/topics)主題。 – dimo414 2017-02-08 00:35:07