- 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.
推薦閱讀
- C語言程序設計案例教程
- Beginning C++ Game Programming
- 控糖控脂健康餐
- Network Automation Cookbook
- Mastering Unity Shaders and Effects
- SQL Server 2016數據庫應用與開發
- Oracle GoldenGate 12c Implementer's Guide
- 響應式Web設計:HTML5和CSS3實戰(第2版)
- JSP程序設計實例教程(第2版)
- C指針原理揭秘:基于底層實現機制
- 每個人的Python:數學、算法和游戲編程訓練營
- 測試工程師Python開發實戰
- Visual C++網絡編程教程(Visual Studio 2010平臺)
- C++程序設計習題與實驗指導
- 數據結構案例教程:C語言版