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!
Reviewing the Blog Module的更多相关文章
- Introducing the Blog Module
Introducing the Blog Module Now that we know about the basics of the zend-mvc skeleton application, ...
- lua MVC框架 Orbit初探
介绍 http://keplerproject.github.io/orbit/ Orbit是lua语言版本的MVC框架. 此框架完全抛弃CGILUA的脚本模型, 支持的应用, 每个应用可以卸载一个单 ...
- iOS应用架构现状分析
iOS从2007年诞生至今已有近10年的历史,10年的时间对iOS技术圈来说足够产生相当可观的沉淀,尤其这几年的技术分享氛围无论国内国外都显得异常活跃.本文就iOS架构这一主题,结合开发圈里讨论较多的 ...
- 【转发】构建高可伸缩性的WEB交互式系统(下)
原文转自:http://kb.cnblogs.com/page/504518/ 本文是<构建高可伸缩性的WEB交互式系统>系列文章的第三篇,以网易的NEJ框架为例,对模块的可伸缩性进行分析 ...
- 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- ...
- Understanding the Router
Understanding the Router Our module is coming along nicely. However, we're not really doing all that ...
- Models and the ServiceManager
Models and the ServiceManager In the previous chapter we've learned how to create a "Hello Worl ...
- 【SF】开源的.NET CORE 基础管理系统 - 安装篇
[SF]开源的.NET CORE 基础管理系统 -系列导航 1.开发必备工具 IDE:VS2017 运行环境:netcoreapp1.1 数据库:SQL Server 2012+ 2.获取最新源代码 ...
- nodeJs 操作Mysql数据库
nodeJs下操作数据库需要安装npm模块: mysql npm install mysql --save-dev 新建express项目 express --view=ejs 在项目根目录下新建数据 ...
随机推荐
- 【Java】Java运行cmd命令直接导出.sql文件
Java中的Runtime.getRuntime().exec(commandStr)可以调用执行cmd命令 package Util; import java.io.File; import jav ...
- DOM事件逐层上机传递
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 什么是MBeanServer
什么是MBeanServer MBeanServer是一个包含所有注册MBean的仓库.它是JMX代理层的核心.JMX1.0规范提供一个接口叫 javax.management.MBeanServer ...
- [Andrew]Ext.net前台弹框
//有询问的提示框 Ext.Msg.show({ title: title, msg: msg, buttons: Ext.Msg.Y ...
- 用js将毫秒时间转成正常时间
1. 将毫秒时间转成正常时间 //#region 将毫秒转换成正常的日期 function getDate(time) { var date = new Date(parseInt(time)); v ...
- 《C Primer Plus 第五版》读书笔记
CH1-2:概述 链接器:链接库代码.启动代码(start-up code) CH3-5:数据.字符串.运算符 1 数据类型存储方式:整数类型.浮点数类型 2 浮点数存储:小数部分+指数部分 3 in ...
- SimpleHttpServer的学习之UML
如何分析一个稍微大点的源码呢? 静态分析 除了看代码,就是 uml图,UML虽然在书本类与类之间的关系很复杂,可能要一本书,但是最核心的其实很简单: (1)继承 extends (2)实现接口 imp ...
- 中断——中断描述符表的定义和初始化(二) (基于3.16-rc4)
上篇博文对中断描述符表(IDT)中异常和非屏蔽中断部分的初始化做了说明,这篇文章将分析外部中断部分的初始化. 在上篇博文中,可以看到,内核在setup_once汇编片段中,对中断和异常部分做了初步的初 ...
- 【转载】c++中的 extern "C"(讲的更好一些)
[说明]本文章转载自 东边日出西边雨 的文章http://songpengfei.iteye.com/blog/1100239 ------------------------------------ ...
- 【Java基础】Java网络编程基础知识
什么是网络编程 网络编程是通过使用套接字来达到进程间通信目的,那什么是套接字呢?其实套接字是支持TCP/IP的网络通信的基本操作单元,可以看做是不同主机之间的进程进行双向通信的端点,简单的说就是通信的 ...