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 在项目根目录下新建数据 ...
随机推荐
- 【转】iOS中16进制转10进制
原文网址:http://www.voidcn.com/blog/u012198553/article/p-4976772.html /// 将十六进制的字符串转化为NSData - (NSData ) ...
- InnoDB关键特性之insert buffer
insert buffer 是InnoDB存储引擎所独有的功能.通过insert buffer,InnoDB存储引擎可以大幅度提高数据库中非唯一辅助索引的插入性能. 数据库对于自增主键值的插入是顺序的 ...
- UVA 11624 Fire! BFS搜索
题意:就是问你能不能在火烧到你之前,走出一个矩形区域,如果有,求出最短的时间 分析:两遍BFS,然后比较边界 #include<cstdio> #include<algorithm& ...
- selenium 处理iframe
这篇关于iframe的文章不错 http://assertselenium.com/2013/02/22/handling-iframes-using-webdriver/ selenium处理ifr ...
- LeetCode题解——Median of Two Sorted Arrays
题目: 找两个排序数组A[m]和B[n]的中位数,时间复杂度为O(log(m+n)). 解法: 更泛化的,可以找第k个数,然后返回k=(m+n)/2时的值. 代码: class Solution { ...
- bzoj 2716 天使玩偶(CDQ分治,BIT)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=29234 [题意] 询问当前点与已知点的最小曼哈顿距离. [思路 ...
- Android字符串相关类 - CharSequence
Class Overview CharSequence定义为public interface.该接口用于表示一个有序字符的集合,并在其中定义里了处理字符的方法. 已知的常用间接子类有String, S ...
- highcharts图表的图例legend怎么改变显示位置
一.将图例Legend放于图表右侧1.设置chart的marginRight属性值:chart: { marginRight: 120}2.设置legend图例属性值如下 legend: { alig ...
- Petshop学习第二天
数据访问层的数据访问设计 1.数据层的内容: 数据库访问.Messaging.membership.Profile四部分 2.数据库对象的分类: 一类:数据实体,对应数据库中相应的数据表,它们作为数据 ...
- jQuery遍历多层json数据
1.json与jsonp的区别(待查) 2.要遍历的数据如下: {"status": "ok", "code": 200, "da ...