最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

原来高焕堂也误用职责链模式ASP技巧

日期:10-31    来源:中国设计秀    作者:cnwebshow.com

   近日 见同事正在看 高焕堂新书 《UML+OOPC 嵌入式C语言开发精讲》偶然发现他对COR模式存在严重误解。b2V中国设计秀
b2V中国设计秀
废话少说 ,具体如下:b2V中国设计秀
b2V中国设计秀
  在他的大作 32.5 章节里 用到该模式b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
代码如下:b2V中国设计秀
b2V中国设计秀
#include "lw_oopc_kc.h"b2V中国设计秀
#include "ex32-il.h"b2V中国设计秀
b2V中国设计秀
CLASS(LED_P0)b2V中国设计秀
{b2V中国设计秀
    IMPLEMENTS(IL);b2V中国设计秀
    void (*init)(LED_P0*);b2V中国设计秀
    IL* next;b2V中国设计秀
};b2V中国设计秀
b2V中国设计秀
CLASS(LED_P1)b2V中国设计秀
{b2V中国设计秀
    IMPLEMENTS(IL);b2V中国设计秀
    void (*init)(LED_P1*);b2V中国设计秀
    IL* next;b2V中国设计秀
};b2V中国设计秀
b2V中国设计秀
CLASS(LED_P2)b2V中国设计秀
{b2V中国设计秀
    IMPLEMENTS(IL);b2V中国设计秀
    void (*init)(LED_P2*);b2V中国设计秀
    IL* next;b2V中国设计秀
};b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
/* EX32-led.c */b2V中国设计秀
#include <REG51F.H>b2V中国设计秀
#include "lw_oopc_kc.h"b2V中国设计秀
#include "ex32-led.h"b2V中国设计秀
b2V中国设计秀
static void init_1(LED_P1* t) {b2V中国设计秀
       t->next = NULL;b2V中国设计秀
//    xxx = 0xf3;b2V中国设计秀
}b2V中国设计秀
b2V中国设计秀
static int pass_1(char ty, char hx, void *t) {b2V中国设计秀
    LED_P1 *cthis = (LED_P1*)t;b2V中国设计秀
    IL* ps = cthis->next;b2V中国设计秀
    if(ty=='1')b2V中国设计秀
         {b2V中国设计秀
           P1 = hx;b2V中国设计秀
           return 1;b2V中国设计秀
         }b2V中国设计秀
    if(ty=='A') P1 = hx;b2V中国设计秀
    if(ps == NULL) return 0;b2V中国设计秀
    else  return ps->pass(ty, hx, ps);b2V中国设计秀
}b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
CTOR(LED_P1)b2V中国设计秀
    FUNCTION_SETTING(init, init_1)b2V中国设计秀
    FUNCTION_SETTING(IL.pass, pass_1)b2V中国设计秀
END_CTORb2V中国设计秀
// ------------------------------- b2V中国设计秀
static void init_0(LED_P0* t) {b2V中国设计秀
       t->next = NULL;b2V中国设计秀
}b2V中国设计秀
b2V中国设计秀
static int pass_0(char ty, char hx, void *t) {b2V中国设计秀
    LED_P0 *cthis = (LED_P0*)t;b2V中国设计秀
    IL* ps = cthis->next;b2V中国设计秀
    if(ty=='0')b2V中国设计秀
         {b2V中国设计秀
           P0 = hx;b2V中国设计秀
           return 1;b2V中国设计秀
         }b2V中国设计秀
    if(ty=='A') P0 = hx;b2V中国设计秀
    if(ps == NULL) return 0;b2V中国设计秀
    else  return ps->pass(ty, hx, ps);b2V中国设计秀
}b2V中国设计秀
b2V中国设计秀
CTOR(LED_P0)b2V中国设计秀
    FUNCTION_SETTING(init, init_0)b2V中国设计秀
    FUNCTION_SETTING(IL.pass, pass_0)b2V中国设计秀
END_CTORb2V中国设计秀
//----------------------------------------b2V中国设计秀
static void init_2(LED_P2* t) {b2V中国设计秀
       t->next = NULL;b2V中国设计秀
}b2V中国设计秀
b2V中国设计秀
static int pass_2(char ty, char hx, void *t) {b2V中国设计秀
    LED_P2 *cthis = (LED_P2*)t;b2V中国设计秀
    IL* ps = cthis->next;b2V中国设计秀
    if(ty=='2')b2V中国设计秀
         {b2V中国设计秀
           P2 = hx;b2V中国设计秀
           return 1;b2V中国设计秀
         }b2V中国设计秀
    if(ty=='A') P2 = hx;b2V中国设计秀
    if(ps == NULL) return 0;b2V中国设计秀
    else  return ps->pass(ty, hx, ps);b2V中国设计秀
}b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
CTOR(LED_P2)b2V中国设计秀
    FUNCTION_SETTING(init, init_2)b2V中国设计秀
    FUNCTION_SETTING(IL.pass, pass_2)b2V中国设计秀
END_CTORb2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
这三个类 就是职责链中的负责处理请求与转发请求的类,但 严重问题是 他们与 请求基本存在一一对应的关系 b2V中国设计秀
b2V中国设计秀
if(ty=='0')b2V中国设计秀
         {b2V中国设计秀
           P0 = hx;b2V中国设计秀
           return 1;b2V中国设计秀
         }b2V中国设计秀
b2V中国设计秀
这是LED_P0的责任, 如果 把'0'换为'1' 则就是  LED_P1的责任  这是我们从代码里发现的, 其实他自己在书里也已经写了(如果ty值为'0',表示这是LED_P0的责任,于是将另一个参数hx值送到P0。如果ty值为'A',表示这是所有对象的都有的责任,。。)   b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
结论:高焕堂完全误解了COR模式 ,其实这些代码散发着 重复的臭味 完全可以重构到表模式 具体如何重构 不用我说了吧??b2V中国设计秀
b2V中国设计秀
  b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
摘自这本书的高焕堂简介:b2V中国设计秀
b2V中国设计秀
     从事IT行业近30年,被称为“台湾OO技术教父级代表人物”;近年来,专注与产业 企业及嵌入式产品的架构设计,被称为b2V中国设计秀
b2V中国设计秀
“台湾软件架构设计大师”。。。。。 b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
b2V中国设计秀
 b2V中国设计秀

本文引用地址:/bc/article_46174.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明