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. (转)理解OAuth 2.0

    转自:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html OAuth是一个关于授权(authorization)的开放网络标准,在全世界得到广泛 ...

  2. Spring入门之HelloSpring

    Spring描述: -轻量级:Spring是非侵入式的-基于Spring开发的应用中的对象可以不依赖于Spring的API -依赖注入(DI---dependency injection,IOC) - ...

  3. Progress 自定义(一)-shape

    需求:自定义ProgressBar,使用系统自定义shape; 效果图: 1.默认底色: 2.第一进度颜色: 3.第二进度颜色: 实现分析: 1.目录结构: 代码实现: 1.progress_styl ...

  4. 018如何建立自动化框架 how to bulid the framwork

    本讲包括: 一. objective 二. How to bulid 三. Keyview of frawork (关键视图) 四. conclusion automation framwork:自动 ...

  5. java 基础之数据类型

    java 数据类型这个地方面试的时候会被经常问到,很多人并不注意这个问题,今天带大家全面了解一下.java数据类型主要分:1.基本数据类型 2.引用数据类型 3.空类型 下面一一介绍. 基本数据类型包 ...

  6. 【原】Storm 守护线程容错机制

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  7. 浅析ado.net获取数据库元数据信息 DeriveParameters

    写这个文章源于早先对ADO.Net获取数据库元数据上的认识,去年我在阅读ADO.Net Core Reference的时候曾经注意过DataSet的FillSchema的这个方法.这方面,在我之前的随 ...

  8. glassfish 一个bug重现

        原文链接:https://java.net/jira/browse/GLASSFISH-21293?jql=project%20%3D%20GLASSFISH%20AND%20resoluti ...

  9. 深入浅出 JavaScript 对象 v0.5

    JavaScript 没有类的概念,因此它的对象与基于类的语言中的对象有所不同.笔者主要参考<JS 高级程序设计>.<JS 权威指南>和<JS 精粹> 本文由浅入深 ...

  10. 解决配置android开发环境eclipse获取ADT获取不到,一直"Pending"

    在安装完Android SDK后eclipse要获取ADT, 可是由于GFW的存在, eclipse经常无法从http://dl-ssl.google.com/android/eclipse 获取到任 ...