- 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.
推薦閱讀
- 一步一步學Spring Boot 2:微服務項目實戰(zhàn)
- Python for Secret Agents:Volume II
- Python入門很簡單
- Cocos2d-x游戲開發(fā):手把手教你Lua語言的編程方法
- 實戰(zhàn)Java程序設(shè)計
- R語言數(shù)據(jù)可視化實戰(zhàn)
- Practical DevOps
- Java Web程序設(shè)計
- Functional Programming in JavaScript
- INSTANT CakePHP Starter
- Unity 5.x By Example
- Python算法從菜鳥到達人
- INSTANT Sinatra Starter
- 微信小程序開發(fā)與實戰(zhàn)(微課版)
- Python語言實用教程