Reviewing the Blog Module

Reviewing the Blog Module

Throughout the tutorial, we have created a fully functional CRUD module using a blog as an example. While doing so, we‘ve made use of several different design patterns and best-practices. Now it‘s time to reiterate and take a look at some of the code samples we‘ve written. This is going to be done in a Q&A fashion.

Do we always need all the layers and interfaces?

Short answer: no.

Long answer: The importance of interfaces increases the bigger your application becomes. If you can foresee that your application will be used by other people or should be extendable, then you should strongly consider creating interfaces and coding to them. This is a very common best-practice that is not tied to Zend Framework specifically, but rather more general object oriented programming.

The main role of the multiple layers that we have introduced are to provide a strict separation of concerns for our application.

It is tempting to include your database access directly in your controllers. We recommend splitting it out to other objects, and providing interfaces for the interactions whenever you can. Doing so helps decouple your controllers from the implementation, allowing you to swap out the implementation later without changing the controllers. Using interfaces also simplifies testing, as you can provide mock implementations easily.

Why are there so many controllers?

With the exception of our ListController, we created a controller for each route we added.

We could have combined these into a single controller. In practice, we have observed the following when doing so:

  • Controllers grow in complexity, making maintenance and additions more difficult.
  • The number of dependencies grows with the number of responsibilities. Many actions may need only a subset of the dependencies, leading to needless performance and resource overhead.
  • Testing becomes more difficult.
  • Re-use becomes more difficult.

The primary problem is that such controllers quickly break the Single Responsibility Principle, and inherit all the problems that principle attempts to combat.

We recommend a single action per controller whenever possible.

Do you have more questions? PR them!

If there‘s anything you feel that‘s missing in this FAQ, please create an issue or send a pull request with your question!

时间: 2024-10-10 09:39:48

Reviewing the Blog Module的相关文章

LEXUS OPENCART 自适应主题模板 ABC-0019-01 HIGHLIGHTED FEA

LEXUS OPENCART 自适应主题模板 ABC-0019-01 HIGHLIGHTED FEATURES FLEXIBLE LAYOUTS – MODULES FEATURES Compatible with Opencart 1.5.4, Opencart 1.5.5, Opencart 1.5.6, 1.5.6.1 Support Wide Screen 1170px, 980px Built-in Pavo Framework Version 2.0 and Bootstrap 3.

lua MVC框架 Orbit初探

介绍 http://keplerproject.github.io/orbit/ Orbit是lua语言版本的MVC框架. 此框架完全抛弃CGILUA的脚本模型, 支持的应用, 每个应用可以卸载一个单独的文件中,当然你也可以将它拆为一个文件, 当你需要时候. 此框架运行在WSAPI协议的服务器上,所以可以工作在 Xavante和一些CGI和fastcgi程序上. Orbit is an MVC web framework for Lua. The design is inspired by li

Maxstore OpenCart 2.X 自适应主题模板 ABC-0653

MAXSTORE OPENCART 2.X 自适应主题模板 ABC-0653 MAXSTORE IS A MULTIPURPOSE BOOSTRAP 3 OPENCART THEME The theme is compatible with Opencart version 1.5.6.x and 2.0.x It is very easy to install and customize. It ships with a powerfull customization panel that i

LEXUS OPENCART 自适应主题模板 ABC-0019-01 HIGHLIGHTED FEATURES

LEXUS OPENCART 自适应主题模板 ABC-0019-01 HIGHLIGHTED FEATURES FLEXIBLE LAYOUTS – MODULES FEATURES Compatible with Opencart 1.5.4, Opencart 1.5.5, Opencart 1.5.6, 1.5.6.1 Support Wide Screen 1170px, 980px Built-in Pavo Framework Version 2.0 and Bootstrap 3.

LEXUS OPENCART 自适应主题模板 ABC-0017 FLEXIBLE LAYOUTS –

LEXUS OPENCART 自适应主题模板 ABC-0017 FLEXIBLE LAYOUTS – MODULES 兼容浏览器 IE8, IE9, IE10, IE11, Firefox, Safari, Opera, Chrome OpenCart版本 OpenCart 2.0.x, OpenCart 1.5.6.x, OpenCart 1.5.5.x, OpenCart 1.5.5, OpenCart 1.5.4 包含文件 Layered PSD, PHP Files, CSS Files

PAV BOOKS OPENCART 商城自适应主题模板 ABC-0018

PAV BOOKS OPENCART 商城自适应主题模板 ABC-0018 FEATURES Compatible with Opencart 1.5.4, Opencart 1.5.5, Opencart 1.5.6, Opencart 1.5.6.1 Support Wide Screen 1170px, 980px -. Built-in Pavo Framework  and Bootstrap HTML5 and CSS3 Support Full Responsive Theme G

opencar模板 opencartchina

LEXUS EXIST COMBO OPENCART 2.X 自适应主题模板 ABC-0553-03FEATURES Compatible with Opencart 1.5.4, Opencart 1.5.5, Opencart 1.5.6, Opencart 1.5.6.1, Opencart 1.6.5.4 Support Wide Screen 1170px, 980px Built-in Pavo Framework Version 3.0 and Bootstrap 3 No Hac

【转发】构建高可伸缩性的WEB交互式系统(下)

原文转自:http://kb.cnblogs.com/page/504518/ 本文是<构建高可伸缩性的WEB交互式系统>系列文章的第三篇,以网易的NEJ框架为例,对模块的可伸缩性进行分析介绍. 实例分析 NEJ框架根据前两篇的描述对此套架构模式做了实现,下面我们用具体实例讲解如何使用NEJ中的模块调度系统来拆分一个复杂系统.开发测试模块.整合系统等. 系统分解 绘制层级关系图 当我们拿到一个复杂系统时,根据交互稿可以绘制出组成系统的模块的层级关系图,并确定系统对外可访问的模块. 抽象依赖关系

Lexus OpenCart 自适应主题模板 ABC-0017

Lexus OpenCart 自适应主题模板 ABC-0017 Flexible Layouts – Modules Highlight Features Features Compatible with Opencart 1.5.4, Opencart 1.5.5, Opencart 1.5.6 Support Wide Screen 1170px, 980px Built-in Pavo Framework Version 2.0 and Bootstrap 3.0 No Hacking C