Strategy和Bridge

先给两个链接备查:

http://www.jdon.com/designpatterns/designpattern_Strategy.htm

http://www.jdon.com/designpatterns/bridge.htm

其实我感觉也没多大区别。这里面还说strategy类似factory呢。其实要真的做一个程序,需要把实现放到各个子类里面的时候,感觉一下子就用了好几个所谓GOF(四人帮)的设计模式:factory你肯定得要吧,子类实现就来了strateggy和Bridge。这实现要是放在全局变量里,那就是singleton呢。封装成一个上级程序不了解内部的实现,那就是Adapter,把两个数据格式匹配起来,那就是facade。万变不离其宗,其实不就是面向对象的继承手段的应用吗。

Castle’s Mission

看到Castle Project的Mission,感觉很好,很安逸。实在是程序员的福音啊。

Castle Project has a well defined mission, that can be easily stated as

To provide a simple set of tools to speed up the development of common enterprise and web applications while promoting good architecture.

We also need to state what we do not want to provide and what we do not want to be labeled:

  • Castle is not a set of classes that must be specialized to create your application. Castle should not force you to adhere to a specific architecture.
  • Castle should not be all-or-nothing. The developer can use the tools he wants to use, and at the same time, use different approaches in different areas of his application in a peaceful manner.
  • Castle should not be configuration-driven, and more important, should not be XML-driven. Configuration should be used only to express external settings, or as a hint to help the application to assemble itself. We shall look forward to delivering self-assemblying capabilities and convention over configuration.

局部变量与全局变量

昨天调程序碰到一个问题:Microsoft JScript runtime error: ‘__pendingCallbacks[…].async’ is null or not an object

google后得到:

http://blog.csdn.net/fanfengchimo/archive/2007/07/20/1700402.aspx

http://www.cnblogs.com/xioxu/archive/2006/11/17/563202.html

原来是微软的代码里这一段i=0使用的是global的。

function WebForm_CallbackComplete() {
    for (i = 0; i < __pendingCallbacks.length; i++) {
        callbackObject = __pendingCallbacks[i];
        if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) {
            WebForm_ExecuteCallback(callbackObject);
            if (!__pendingCallbacks[i].async) {

其实由于js是弱类型语言,大家都习惯于直接上来就用一个变量,而不是用var声明。缺点来了吧:即使是我不用变量i,如果在callback回来的处理函数再去callback,也会出现问题。WebForm_ExecuteCallback(callbackObject);
就有可能改变global i的值。

所以这还是一个潜在的bug.幸好对我来说,并没有callback调用callback,只需要用i的时候加上var声明就可以解决。