Miscellaneous

依赖注入(DI) 和 控制反转(IoC)

首先依赖注入和控制反转说的是同一个东西,是一种设计模式,这种设计模式用来减少程序间的耦合,下面就以php的角度来描述一下依赖注入这个概念。 先假设我们这里有一个类,类里面需要用到数据库连接,按照最最原始的办法,我们可能是这样写这个类的: 过程: 在构造函数里先将数据库类文件include进来; 然后又通过new Db并传入数据库连接信息实例化db类; 之后getList方法就可以通过$this->_db来调用数据库类,实现数据库操作。 看上去我们实现了想要的功能,但是这是一个噩梦的开始,以后example1,example2,example3....越来越多的类需要用到db组件,如果都这么写的话,万一有一天数据库密码改了或者db类发生变化了,岂不是要回头修改所有类文件? ok,为了解决这个问题,工厂模式出现了,我们创建了一个Factory方法,并通过Factory::getDb()方法来获得db组件的实例: sample类变成: 这样就完美了吗?再次想想一下以后example1,example2,example3.......

关于IOC 控制反转

1. IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑。 图1:软件系统中耦合的对象 如果我们打开机械式手表的后盖,就会看到与上面类似的情形,各个齿轮分别带动时针、分针和秒针顺时针旋转,从而在表盘上产生正确的时间。图1中描述的就是这样的一个齿轮组,它拥有多个独立的齿轮,这些齿轮相互啮合在一起,协同工作,共同完成某项任务。我们可以看到,在这样的齿轮组中,如果有一个齿轮出了问题,就可能会影响到整个齿轮组的正常运转。 齿轮组中齿轮之间的啮合关系,与软件系统中对象之间的耦合关系非常相似。对象之间的耦合关系是无法避免的,也是必要的,这是协同工作的基础。现在,伴随着工业级应用的规模越来越庞大,对象之间的依赖关系也越来越复杂,经常会出现对象之间的多重依赖性关系,因此,架构师和设计师对于系统的分析和设计,将面临更大的挑战。对象之间耦合度过高的系统,必然会出现牵一发而动全身的情形。 图2:对象之间复杂的依赖关系 耦合关系不仅会出现在对象与对象之间,也会出现在...

Fix Opencart Fedex Shipping Error

I'm using Opencart 1.5.6.4 and the default FedEx module doesn't display any shipping options during checkout. I changed code and get response message: After contact with FedEx technical support, i found the problem is caused by StateOrProvinceCode. The script use Zone Name as value, but it need to use Zone Code. For example, after we change 'Ontario' to 'ON', the FedEx shipping options can success list during checkout. All you need to do is open file 'catalog/model/shippin...

Netbeans 中文乱码 输入变方格

出现这个问题可能下面几个原因: 1、项目编码为utf-8,但是netbeans默认为gbk 打开netbeans安装目录,找到etc目录下的netbeans.conf文件,打开文件,可以看到netbeans_default_options这个配置选项,在后面加上“-J-Dfile.encoding=UTF-8”这个选项就可以了。 2、检查字体是否支持中文 有些字体不支持中文,输入中文,就会显示方格之类的符号,打开netbeans,工具->选项->字体和颜色 换一个支持中文的字体试试。

Remove VirtualBox RPM Package in Fedora

First, you need to find the RPM package name, just run something like this: Remove the package Remove kmod related files If you plan to install a new version of VirtualBox, checkout this link: http://www.tecmint.com/install-virtualbox-on-redhat-centos-fedora/

How to expand/adjustable iframe height

Works fine in all browsers.

Set Netbeans user Interface language in Windows

Don't know why NetBeans not has an option to choose the user interface language, it use the Windows system language as the default. It took me a while to figure out how to change the interface language. 1. Temporary Solution 2. Permanent Solution Go to Netbeans installation directory, for example, C:\\Program Files\7.1.1\etc Open "netbeans.conf" and find netbeans default option line

Create web server on Mac

Apache Start Apache Check it's working: http://localhost/ PHP In /etc/apache2/httpd.conf, uncomment this line: Restart Apache Fix a warning appearing in phpinfo() Create /etc/php.ini and make it writable In php.ini, find this line: Uncomment it and insert your time zone (http://php.net/manual/en/timezones.php) Restart Apache MySQL Download the MySQL package for Mac OS X.5 (32 or 64 bits depending on your machine) Install everything in...

Learn English 2011

Online shopping is the best thing since sliced bread! Online shopping is a new way to shop - so someone "invented/discovered/developed" this new way to shop. Many years ago people ate bread but the bread was not sliced, so they had to pull the bread apart using their hands. Then someone invented/discovered/developed a new way to make the bread easier to handle - they cut the loaf into slices of bread. That was a small invention - not the most important invention in the history of the world, bu...

20 Tools to Improve Your Website’s Usability

Usability testing is test conducted to collect feedback and information from your website’s visitors or regular readers that can be very useful for future website revamp, enhancement or other adjustments. Designers and developers may have created websites according to specifications, but ultimately it is the users who will decide its creditability (how far it is usable), the highlights of the site and what does it lack of. How to know whether a visitor likes your website? Usability ...