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!

Reviewing the Blog Module的更多相关文章

  1. Introducing the Blog Module

    Introducing the Blog Module Now that we know about the basics of the zend-mvc skeleton application, ...

  2. lua MVC框架 Orbit初探

    介绍 http://keplerproject.github.io/orbit/ Orbit是lua语言版本的MVC框架. 此框架完全抛弃CGILUA的脚本模型, 支持的应用, 每个应用可以卸载一个单 ...

  3. iOS应用架构现状分析

    iOS从2007年诞生至今已有近10年的历史,10年的时间对iOS技术圈来说足够产生相当可观的沉淀,尤其这几年的技术分享氛围无论国内国外都显得异常活跃.本文就iOS架构这一主题,结合开发圈里讨论较多的 ...

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

    原文转自:http://kb.cnblogs.com/page/504518/ 本文是<构建高可伸缩性的WEB交互式系统>系列文章的第三篇,以网易的NEJ框架为例,对模块的可伸缩性进行分析 ...

  5. Making Use of Forms and Fieldsets

    Making Use of Forms and Fieldsets So far all we have done is read data from the database. In a real- ...

  6. Understanding the Router

    Understanding the Router Our module is coming along nicely. However, we're not really doing all that ...

  7. Models and the ServiceManager

    Models and the ServiceManager In the previous chapter we've learned how to create a "Hello Worl ...

  8. 【SF】开源的.NET CORE 基础管理系统 - 安装篇

    [SF]开源的.NET CORE 基础管理系统 -系列导航 1.开发必备工具 IDE:VS2017 运行环境:netcoreapp1.1 数据库:SQL Server 2012+ 2.获取最新源代码 ...

  9. nodeJs 操作Mysql数据库

    nodeJs下操作数据库需要安装npm模块: mysql npm install mysql --save-dev 新建express项目 express --view=ejs 在项目根目录下新建数据 ...

随机推荐

  1. 【转】UIColor对颜色的自定义

    原文网址:http://blog.sina.com.cn/s/blog_5f19ccb10101bhqh.html 在iOS开发中,我们使用UIColor来对我们的界面进行颜色设置,一般我们通过以下两 ...

  2. window.location.search作用

    window.location.search.substr(1).split("&") 这里面的相关属性和时间还有参数能具体说明一下吗?window.location wi ...

  3. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.7

    Prove that for any vectors $$\bex u_1,\cdots,u_k,\quad v_1,\cdots,v_k, \eex$$ we have $$\bex |\det(\ ...

  4. MFC菜单、工具栏和状态栏

    菜单:CMenu类 CMenu类的主要成员函数 BOOL LoadMenu(UINT nIDResource); 加载菜单资源,并将其附加到CMenu对象上.参数nIDResource指定了要加载的菜 ...

  5. 【转】C数据存储(包括const存储在哪,C++不同部分我在文中用红字已指出)

    非原创(文中红字为自己见解,如有不对,请大神指点) 程序由指令和数据组成,C语言程序亦是如此.开发者在编写程序的时候往往需要根据不同数据的特点以及程序需求来选择不同的数据存储方式,那么在C语言中数据的 ...

  6. Spring MVC @ModelAttribute

    1.@ModelAttribute注释void返回值的方法 @Controller public class HelloModelController { @ModelAttribute public ...

  7. 【转载】解析提高PHP执行效率的50个技巧

    1.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量, 单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的”函数”(译注:PHP手 ...

  8. ThinkPHP中SQL调试方法

    $admin = D('Admin'); $info = $admin->field('`lastlogintime`,`lastloginip`')->where(array('user ...

  9. DNN学习

    DNN(DotNetNuke)是一个免费.开源.可扩展的内容管理系统,可广泛用于商务网站.企业内网和外网网站.在线内容发布网站.DotNetNuke是微软第一次向开源说"Yes"的 ...

  10. 在KVM虚拟机中使用spice系列之二(USB映射,SSL,密码,多客户端支持)

    在KVM虚拟机中使用spice系列之二(USB映射,SSL,密码,多客户端支持) 发布时间: 2015-02-27 00:16 1.spice的USB重定向 1.1 介绍 使用usb重定向,在clie ...