- 浏览: 55138 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
luoiori:
职场比拼的是综合素质,而不是专能。
受教了
应对老板 -
biqing0427:
不过最近改变主意了,目前流行光头。
假如有一天不做程序员,我最想做的职业是什么? -
linkerlin:
推荐C++/CLI
关于c#调用C++代码的一些应用的体会 -
ray_linn:
CharSet 注意 不要轻易使用 unicode.....
...
关于c#调用C++代码的一些应用的体会 -
lyong757:
正准备做一个c的库函数转到C# 看看 不说话
关于c#调用C++代码的一些应用的体会
早上一到公司就看到德国那边的新需求,唉,没办法我们睡觉做着美梦的时候,那边正在想着让我们怎么工作充实呢。别人安排完了睡觉,我们醒来就要完成别人想的,没有办法,工作嘛,就这样了……
德国那边通常会把一个项目给我们中国这边的一个经理,然后经理安排developers开发各自的模块,然后最后自己组装各个模块,形成产品。德国那边不管我们怎么分工的,最后他们只要成品的。
这种工作模式 其实有点像builder的,各个模块分开,最后组装。不过今天这里我想用下composite模式。
1.组件:Component 一个工作组
2.项目经理:Composite 负责组装 和 德国的交互
3.小组成员A,B,C,D
4.看看整个过程吧:
结果如下:
call leafA.add()
call leafB.add()
call leafC.add()
call leafD.add()
composite.add(a):450
call leafA.del()
call leafB.del()
call leafC.del()
call leafD.del()
composite.del(a):50
call leafA.mul()
call leafB.mul()
call leafC.mul()
call leafD.mul()
composite.mul(a):3628800
composite removes leafA
call leafB.add()
call leafC.add()
call leafD.add()
composite.add(a):405
call leafB.del()
call leafC.del()
call leafD.del()
composite.del(a):45
call leafB.mul()
call leafC.mul()
call leafD.mul()
composite.mul(a):3265920
directly ask leafB
call leafB.add()
composite.add(a):90
call leafB.del()
composite.del(a):10
call leafB.mul()
composite.mul(a):725760
德国那边通常会把一个项目给我们中国这边的一个经理,然后经理安排developers开发各自的模块,然后最后自己组装各个模块,形成产品。德国那边不管我们怎么分工的,最后他们只要成品的。
这种工作模式 其实有点像builder的,各个模块分开,最后组装。不过今天这里我想用下composite模式。
1.组件:Component 一个工作组
public abstract class Component { public abstract int add(int a[]);//假设产品加的功能 public abstract int del(int a[]);//假设产品减的功能 public abstract int mul(int a[]);//假设产品乘的功能 public void addComponent(Component comp) { };//负责增加小组成员 public void removeComponent(Component comp) { };//负责减少小组成员 public Component getChildComponent(int i) { return null; };//得到小组成员,这样可以直接和他进行对话 }
2.项目经理:Composite 负责组装 和 德国的交互
import java.util.ArrayList; import java.util.List; public class Composite { List leaf = new ArrayList(); //组装加的功能 public int add(int a[]){ int iResult = 0; for(int i=0;i<leaf.size();i++){ iResult +=((Component)leaf.get(i)).add(a); } return iResult; }; //组装减的功能 public int del(int a[]){ int iResult = 0; for(int i=0;i<leaf.size();i++){ iResult +=((Component)leaf.get(i)).del(a); } return iResult; }; //组装乘的功能 public int mul(int a[]){ int iResult = 0; for(int i=0;i<leaf.size();i++){ iResult +=((Component)leaf.get(i)).mul(a); } return iResult; }; //增加小组成员 public void addComponent(Component comp) { leaf.add(comp); }; //减少小组成员 public void removeComponent(Component comp) { int i = leaf.indexOf(comp); if(i>=0){ leaf.remove(i); } }; //提供德国那边直接和某个成员直接交互 public Component getChildComponent(int i) { Component comp = null; if(leaf.size()>0&&i<leaf.size()){ comp = (Component)leaf.get(i); } return comp; }; }
3.小组成员A,B,C,D
//小组成员A public class LeafA extends Component { public int add(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult += a[i]; } System.out.println("call leafA.add()"); return iResult; } public int del(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult = a[i] - iResult; } System.out.println("call leafA.del()"); return iResult; } public int mul(int a[]) { int iResult = 1; for (int i = 0; i < a.length; i++) { iResult = iResult * a[i]; } System.out.println("call leafA.mul()"); return iResult; } } //小组成员B public class LeafB extends Component { public int add(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult += a[i]; } System.out.println("call leafB.add()"); return iResult * 2; } public int del(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult = a[i] - iResult; } System.out.println("call leafB.del()"); return iResult * 2; } public int mul(int a[]) { int iResult = 1; for (int i = 0; i < a.length; i++) { iResult = iResult * a[i]; } System.out.println("call leafB.mul()"); return iResult * 2; } } //小组成员C public class LeafC extends Component { public int add(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult += a[i]; } System.out.println("call leafC.add()"); return iResult * 3; } public int del(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult = a[i] - iResult; } System.out.println("call leafC.del()"); return iResult * 3; } public int mul(int a[]) { int iResult = 1; for (int i = 0; i < a.length; i++) { iResult = iResult * a[i]; } System.out.println("call leafC.mul()"); return iResult * 3; } } //小组成员D public class LeafD extends Component { public int add(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult += a[i]; } System.out.println("call leafD.add()"); return iResult * 4; } public int del(int a[]) { int iResult = 0; for (int i = 0; i < a.length; i++) { iResult = a[i] - iResult; } System.out.println("call leafD.del()"); return iResult * 4; } public int mul(int a[]) { int iResult = 1; for (int i = 0; i < a.length; i++) { iResult = iResult * a[i]; } System.out.println("call leafD.mul()"); return iResult * 4; } }
4.看看整个过程吧:
public void testComposite() { Composite composite = new Composite();//任命项目经理 LeafA leafA = new LeafA();//成员A LeafB leafB = new LeafB();//成员B LeafC leafC = new LeafC();//成员C LeafD leafD = new LeafD();//成员D composite.addComponent(leafA);//将A加入项目 composite.addComponent(leafB);//将A加入项目 composite.addComponent(leafC);//将A加入项目 composite.addComponent(leafD);//将A加入项目 int a[] = {1,2,3,4,5,6,7,8,9}; //composite.add(a);德国要求得到加的功能 System.out.println("composite.add(a):"+composite.add(a)); //composite.del(a);德国要求得到减的功能 System.out.println("composite.del(a):"+composite.del(a)); //composite.mul(a);德国要求得到乘的功能 System.out.println("composite.mul(a):"+composite.mul(a)); composite.removeComponent(leafA); //composite.add(a);LeafA 离职了 System.out.println("composite removes leafA"); System.out.println("composite.add(a):"+composite.add(a)); //composite.del(a); System.out.println("composite.del(a):"+composite.del(a)); //composite.mul(a); System.out.println("composite.mul(a):"+composite.mul(a)); //composite.add(a);德国那边要求详细看看B的工作情况 LeafB b = (LeafB)composite.getChildComponent(0); System.out.println("directly ask leafB"); System.out.println("composite.add(a):"+b.add(a)); //composite.del(a); System.out.println("composite.del(a):"+b.del(a)); //composite.mul(a); System.out.println("composite.mul(a):"+b.mul(a)); }
结果如下:
call leafA.add()
call leafB.add()
call leafC.add()
call leafD.add()
composite.add(a):450
call leafA.del()
call leafB.del()
call leafC.del()
call leafD.del()
composite.del(a):50
call leafA.mul()
call leafB.mul()
call leafC.mul()
call leafD.mul()
composite.mul(a):3628800
composite removes leafA
call leafB.add()
call leafC.add()
call leafD.add()
composite.add(a):405
call leafB.del()
call leafC.del()
call leafD.del()
composite.del(a):45
call leafB.mul()
call leafC.mul()
call leafD.mul()
composite.mul(a):3265920
directly ask leafB
call leafB.add()
composite.add(a):90
call leafB.del()
composite.del(a):10
call leafB.mul()
composite.mul(a):725760
发表评论
-
烟花中的模式设想
2010-02-21 19:30 823过年过节放鞭炮,烟花是中国的传统风俗。不 ... -
我工作的那点事--学习《设计模式》实例应用(Chain of Responsibility模式)
2009-02-09 20:10 0面试的流程:人事经理->技术经理->技术总监-&g ... -
水煮烟火-烟花中的模式
2009-02-09 19:02 866过年过节放鞭炮,烟花是中国的传统风俗。不仅可以烘 ... -
我工作的那点事--学习《设计模式》实例应用(decorator模式)
2008-01-24 12:52 1231今天是我们公司写周报的日子,又要回顾一下一周的工作、学习 ... -
我工作的那点事--学习《设计模式》实例应用(Observer模式)
2008-01-24 12:48 916今天早上一到公司,看到公司人事群发过来的邮件,通知下午开 ... -
我工作的那点事--学习《设计模式》实例应用(Adapter模式)
2008-01-24 12:46 1188一想到这个模式,我就想到一个谚语“挂羊头卖狗肉”,哈哈 ... -
我工作的那点事--学习《设计模式》实例应用(Facade模式)
2008-01-24 12:40 954昨天和公司签合同,一沓厚厚的文件,各种条例,感觉自己被束 ... -
我工作的那点事--学习《设计模式》实例应用(Singleton模式)
2008-01-24 12:36 883今天早上开会,要打印一堆文件(先打印出来 然后再复印(M ... -
我工作的那点事--学习《设计模式》实例应用(Builder模式)
2008-01-24 12:33 1018今天无意中在抽屉里发现以前的工资条,看见上面的各项:基本工资, ... -
我工作的那点事--学习《设计模式》实例应用(Prototype模式)
2008-01-24 12:29 986这个模式比较好理解,应用也比较广泛的,说白了就是将别的 ... -
我工作的那点事--学习《设计模式》实例应用(factory模式)
2008-01-24 12:25 893如果您的公司效率不好,或者现在的公司不太适合你,要为以后做 ... -
我工作的那点事--学习《设计模式》实例应用(Mediator模式)
2008-01-24 12:24 831最近因为保险上面问题,为了核实工作的是否为自己交保险, ... -
我工作的那点事--学习《设计模式》实例应用(strategy模式)
2008-01-24 12:22 809最近比较郁闷,公司的人事方面不是很如意。 她在 ... -
Memento模式与Prototype模式结合
2008-01-24 12:18 795我在另一个网站上的文章: http://www.matrix. ... -
我工作的那点事--设计模式实例应用(Command模式)
2008-01-24 11:00 1628好长时间没有学习设计模式了,主要是最近一直在忙德国的一 ...
相关推荐
因此我们欢迎广大读者的批评与指正,无论从书中采用的实例、参考,还是我们遗漏的已知应用,或应该包含的设计模式等方面。你可以通过Addison-Wesley写信给我们,或发送电子邮件到:design-patterns@cs.uiuc.edu。你...
1.1什么是设计模式 2 1.2设计模式的作用 3 1.3GRASP模式的分类 4 1.4GoF设计模式的分类 4 1.5模式的学习阶段 6 第2章负责任地设计对象——GRASP 9 2.1InformationExpert(信息专家) 11 2.2Creator(创造者)...
1.1 什么是设计模式 2 1.2 Smalltalk MVC 中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 指定对象...
1.1什么是设计模式 2 1.2设计模式的作用 3 1.3GRASP模式的分类 4 1.4GoF设计模式的分类 4 1.5模式的学习阶段 6 第2章负责任地设计对象——GRASP 9 2.1InformationExpert(信息专家) 11 2.2Creator(创造者)...
本书设计实例从面向对象的设计中精选出23个设计模式,总结了面向对象设计中最有价值的经验,并且用简洁可复用的形式表达出来。本书分类描述了一组设计良好,表达清楚的软件设计模式,这些模式在实用环境下有特别有用...
1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 指定对象...
摘要:数字地图制图实际上是...文中从数字地图制图软件的需求出发,对制图软件设计中常用设计模式(包括MVC模式、OBSERVER模式、COMPOSITE模式、COMMAND模式)的一般原理和结构进行简要介绍,并通过实例进行具体的说明。
这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用 new 运算符直接实例化对象。这使得程序在判断针对某个给定实例需要创建哪些对象时更加灵活。 工厂模式(Factory Pattern) 抽象工厂模式...
本书设计实例从面向对象的设计中精选出23个设计模式,总结了面向对象设计中最有价值的经验,并且用简洁可复用的形式表达出来。本书分类描述了一组设计良好,表达清楚的软件设计模式,这些模式在实用环境下有特别有用...
这种类型的设计模式属于结构型模式,它创建了对象组的树形结构。 这种模式创建了一个包含自己对象组的类。该类提供了修改相同对象组的方式。 我们通过下面的实例来演示组合模式的用法。实例演示了一个组织中员工的...
1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 指定对象...
1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 ...
最出名的设计模式,语言诙谐明了。 目 录 序言 前言 读者指南 第1章 引言 1 1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决...
1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 指定对象...
1.2 Smalltalk MVC中的设计模式 1.3 描述设计模式 1.4 设计模式的编目 1.5 组织编目 1.6 设计模式怎样解决设计问题 1.7 怎样选择设计模式 1.8 怎样使用设计模式 第二章 实例研究:设计一个文档编辑器 2.1 设计问题...
1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 指定对象...
为能和大家能共同探讨"设计模式",我将自己在学习中的心得写下来,只是想帮助更多人更容易理解 GoF 的《设计模式》。由 于原著都是以C++为例, 以Java为例的设计模式基本又都以图形应用为例,而我们更关心Java在中间件等...
1.1 什么是设计模式 2 1.2 Smalltalk MVC中的设计模式 3 1.3 描述设计模式 4 1.4 设计模式的编目 5 1.5 组织编目 7 1.6 设计模式怎样解决设计问题 8 1.6.1 寻找合适的对象 8 1.6.2 决定对象的粒度 9 1.6.3 指定对象...
5、 、 SINGLETON —俺有 6 个漂亮的老婆, 她们的老公都是我, 我就是我们家里的老公 Sigleton, 她们只要说道“老公”,都是指的同一个人,那就是我(刚才做了个梦啦,哪有这么好的事) 单例模式: 而且自行实例...