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 在项目根目录下新建数据 ...
随机推荐
- 前端的小Demo——涉及keyCode
以下是我的代码: <!doctype html> <html> <head> <meta charset="utf-8"> < ...
- 怎么找到MyEclipse->add struts capabilities
问:MyEclipse:我的工程右键可以MyEclipse->add struts capabilities之前有,后来不知怎么就没有了,谁知道怎么弄出来是struts 答:你已经add过一次了 ...
- Sharepoint网站创建自定义导航全记录
转:http://tech.it168.com/a2009/1207/820/000000820524_all.shtml [IT168 技术文档]在一个Sharepoint网站中可以创建子网站,页面 ...
- Ext入门学习系列(四)面板控件
第四章 使用面板 上节学习了Ext复杂对话框,更进一步了解了Ext的运行机制.本章重点来了解Ext所有控件的基础——面板控件. 一.Ext的面板是什么? 同样先来看看几个效果: 基本面板,点击右上角小 ...
- 将java应用程序打包成可执行文件
准备工作:我用的打包软件是installanywhere.因此要先下载这个软件,这里提供一个下载地址http://www.52z.com/soft/21747.html.(网页上写的有破解方法) 详细 ...
- LR参数化设置(转)
LR学习笔记---参数设置 2010-10-20 14:58:55| 分类: 默认分类|举报|字号 订阅 LR在录制程序运行的过程中,VuGen(脚本生成器) 自动生成了包含录制过程中实际用 ...
- ABAP开发基础知识:内表(Internal Table)
http://www.cnblogs.com/foxting/archive/2012/03/19/2406830.html 内表与结构体基本类似,它同样是程序运行中被临时创建的一个存储空间,它是一个 ...
- 教程-Delphi编译就报毒
这几天都在忙专周实验,今天用到delphi,一到编译时nod32就报毒,编译空文件也报毒,上网查了资料才明白,是编译文件被感染了,生成软件就会报毒.把自己找到的资料分享如下: 重新编译时,生成的e ...
- 1N系列稳压二极管参数
1N系列稳压二极管参数 型号 稳定电压 型号 稳定电压 型号 稳定电压 1N5236 7.5 1N5738 12 1N6002 12 1N5237 8.2 1N5739 13 1N6003 13 1N ...
- iOS CAShapeLayer精讲
前言 CAShapeLayer继承自CALayer,因此,可使用CALayer的所有属性.但是,CAShapeLayer需要和贝塞尔曲线配合使用才有意义. 关于UIBezierPath,请阅读文章:i ...