- Drupal 8 Module Development
- Daniel Sipos
- 121字
- 2021-07-02 12:22:38
Services
Why don't I like this approach?
I don't want the Controller making decisions on how to greet my users. First of all, because Controllers need to stay lean. I want my users to be greeted a bit more dynamically, depending on the time of day, and that will increase the complexity. Second of all, maybe I will want this greeting to be done elsewhere as well, and there is no way I am copying and pasting this logic somewhere else, nor am I going to misuse the Controller just to be able to call that method. The solution? We delegate the logic of constructing the greeting to a service and use that service in our Controller to output the greeting.
推薦閱讀
- Unity 2020 By Example
- Getting Started with Gulp(Second Edition)
- Beginning Java Data Structures and Algorithms
- 微服務與事件驅動架構
- Learning AWS Lumberyard Game Development
- BIM概論及Revit精講
- Getting Started with LLVM Core Libraries
- 從零開始學Linux編程
- 新一代SDN:VMware NSX 網絡原理與實踐
- Django 3.0應用開發詳解
- 深入實踐Kotlin元編程
- Learning Kotlin by building Android Applications
- 關系數據庫與SQL Server 2012(第3版)
- Mastering ArcGIS Server Development with JavaScript
- Java EE程序設計與開發實踐教程