什么是DCI
目录
备注什么是DCI?如何将Role注入到Data中?开发期注入字节码增强MixinTraitTemplateT4 + 部分类 + 显式接口实现 + 扩展类型,C#专用运行期注入Mixin动态代理为什么要用DCI?DCI在C#种的两种实现第一种:显式接口实现 + 部分类第二种实现:组合备注
备注返回目录
之前把DCI的Role和四色原型的Role给弄混了,本文也不会比较这两种Role的区别(后面有机会再说),这里简单的记录一下对DCI的理解。
参考文章:http://www.cnblogs.com/happyframework/p/3302238.html。
什么是DCI?返回目录
Context 选择 Data,让 Data 扮演 Role 执行 Interaction。

Data
用户模型(只包含数据和本地方法)。
如:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace DCIStudy.V7
8 {
9 public partial class People
10 {
11 public string Name { get; set; }
12
13 public TRole Act<TRole>()
14 where TRole : class
15 {
16 return this as TRole;
17 }
18 }
19 }

Context
面向用例设设计,职责为:选择对象,让对象扮演角色,让角色执行交互。
如:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace DCIStudy.V7.Company
8 {
9 public class CompanyContext
10 {
11 public void Execute()
12 {
13 //选择对象。
14 var steven = new People { Name = "Steven" };
15
16 //扮演角色。
17 var developer = steven.Act<IDeveloper>();
18
19 //执行交互。
20 developer.Coding();
21 }
22 }
23 }

Interaction
角色的行为驱动用例的执行。
如:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 using DCIStudy.V7.Company;
8
9 namespace DCIStudy.V7
10 {
11 public partial class People : IDeveloper
12 {
13 void IDeveloper.Coding()
14 {
15 Console.WriteLine(string.Format("{0},快乐的编程中!",this.Name));
16 }
17 }
18 }

如何将Role注入到Data中?返回目录
开发期注入返回目录
字节码增强返回目录
下文的语法是AspectJ吗?我没有验证,有懂的朋友给我留言,我感觉字节码增强是可以实现的。

Mixin返回目录
http://www.cnblogs.com/happyframework/archive/2013/04/25/3040461.html。
Trait返回目录
Trait本质上是一种Mixin的实现,Scala和Php5.4在语法级别支持了trait。
http://php.net/manual/en/language.oop5.traits.php。
Template返回目录
http://www.cnblogs.com/stephen-liu74/archive/2012/08/12/2635583.html。
T4 + 部分类 + 显式接口实现 + 扩展类型,C#专用返回目录
后面会给出示例,因为T4 + 扩展类型都是为了复用的,后文只给出显示接口实现 + 部分类的代码,如果有复用需求,可以引入T4 + 扩展类型。
运行期注入返回目录
Mixin返回目录
Mixin也分开发期间Mixin和运行期间Mixin。
凡是支持OpenClass的语言都支持运行期间Mixin,如:Ruby、Python和Javascript。OpenClass的本质是运行期间可以修改类型系统,也叫“动态类型”,像Php这种静态类型语言就没有这个特性,虽然Php是弱类型和解释执行的。
http://www.cnblogs.com/happyframework/archive/2013/04/25/3040461.html(重点看Ruby)。
动态代理返回目录
http://www.cnblogs.com/happyframework/p/3295853.html
为什么要用DCI?返回目录
如果将DCI作为一种编程模式或设计模式的话,我是比较认可的,作为一种架构模式,还有待考量,等有机会用一下再做评价。
DCI在C#种的两种实现返回目录
第一种:显式接口实现 + 部分类返回目录
项目结构

代码(给出一个上下文的代码)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace DCIStudy.V7.Home
8 {
9 public class HomeContext
10 {
11 public void Execute()
12 {
13 //选择对象。
14 var steven = new People { Name = "Steven" };
15
16 //扮演角色。
17 var player = steven.Act<IPlayer>();
18
19 //执行交互。
20 player.Play();
21 }
22 }
23 }
24
25 using System;
26 using System.Collections.Generic;
27 using System.Linq;
28 using System.Text;
29 using System.Threading.Tasks;
30
31 namespace DCIStudy.V7.Home
32 {
33 public interface IPlayer
34 {
35 void Play();
36 }
37 }
38
39 using System;
40 using System.Collections.Generic;
41 using System.Linq;
42 using System.Text;
43 using System.Threading.Tasks;
44
45 using DCIStudy.V7.Home;
46
47 namespace DCIStudy.V7
48 {
49 public partial class People : IPlayer
50 {
51 void IPlayer.Play()
52 {
53 Console.WriteLine(string.Format("{0},疯狂的游戏中!",this.Name));
54 }
55 }
56 }
57
58 using System;
59 using System.Collections.Generic;
60 using System.Linq;
61 using System.Text;
62 using System.Threading.Tasks;
63
64 namespace DCIStudy.V7
65 {
66 public partial class People
67 {
68 public string Name { get; set; }
69
70 public TRole Act<TRole>()
71 where TRole : class
72 {
73 return this as TRole;
74 }
75 }
76 }

第二种实现:组合返回目录
项目结构

代码(给出一个上下文的代码)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace DCIStudy.V8.Company
8 {
9 public class CompanyContext
10 {
11 public void Execute()
12 {
13 //选择对象。
14 var steven = new People { Name = "Steven" };
15
16 //扮演角色。
17 var developer = steven.Act<Developer>();
18
19 //执行交互。
20 developer.Coding();
21 }
22 }
23 }
24
25 using System;
26 using System.Collections.Generic;
27 using System.Linq;
28 using System.Text;
29 using System.Threading.Tasks;
30
31 namespace DCIStudy.V8.Company
32 {
33 public class CompanyContext
34 {
35 public void Execute()
36 {
37 //选择对象。
38 var steven = new People { Name = "Steven" };
39
40 //扮演角色。
41 var developer = steven.Act<Developer>();
42
43 //执行交互。
44 developer.Coding();
45 }
46 }
47 }
48
49 using System;
50 using System.Collections.Generic;
51 using System.Linq;
52 using System.Text;
53 using System.Threading.Tasks;
54
55 namespace DCIStudy.V8
56 {
57 public class People
58 {
59 public string Name { get; set; }
60
61 public TRole Act<TRole>()
62 where TRole : class
63 {
64 var role = Activator.CreateInstance<TRole>();
65
66 (role as dynamic).People = this;
67
68 return role;
69 }
70 }
71 }

备注返回目录
相对于DDD,DCI给出的模式显得过于泛化了,如:分层、分区(BondedContext)、每个层有哪些元素、如何交互等,DCI、四色原型和DDD应该可以以某种形式融合,有待慢慢思考。
什么是DCI的更多相关文章
- DDD为何叫好不叫座?兼论DCI与业务分析的方法论
今天,仔细阅读了园子里面的一个朋友写的<一缕阳光:DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)?>(http://www.cnblogs.com/ ...
- DCI架构
提出的文章:DCI架构:一个面向对象编程的新图景 http://wenku.baidu.com/view/a7b5e401de80d4d8d15a4fed.html http://www.360doc ...
- 自研DCI网络路由交换协议DCIP-白牌交换机时代的企业网络
一转眼从听华为3Com的路由交换课程到如今已经13年有余了,依稀记得第一节课的时候我带着老婆去听的课(老婆是日语系的.那时还是女朋友,并不懂网络,仅仅是跟着我去上课的).抢了个头排,讲师宋岩老师提问了 ...
- DCI改进,发布后作业乱码不能打开
1.发布后作业不能打开问题,找到com.comsys.net.cn.dci.ui.dialog.PublishesDialog 的960行,改为这样: //以前没有指定文件编码前,采用系统默认编码 / ...
- DCI:DCI学习总结
备注 之前把DCI的Role和四色原型的Role给弄混了,本文也不会比较这两种Role的区别(后面有机会再说),这里简单的记录一下对DCI的理解. 参考文章:http://www.cnblogs.co ...
- DCI:The DCI Architecture: A New Vision of Object-Oriented Programming
SummaryObject-oriented programming was supposed to unify the perspectives of the programmer and the ...
- 达梦DCI
/************************************************************************/ /* DCI编程实例 */ /********** ...
- DCI架构是如何解决DDD战术建模缺点的?
摘要:将DCI架构总结成一句话就是:领域对象(Object)在不同的场景(Context)中扮演(Cast)不同的角色(Role),角色之间通过交互(Interactive)来完成具体的业务逻辑. 本 ...
- 转:VIVADO使用技巧:设置DCI与内部参考电压
本文转自:Vivado使用技巧(12):设置DCI与内部参考电压 - 灰信网(软件开发博客聚合) (freesion.com) DCI与内部参考电压 Xilinx FPGA提供了DCI(Digital ...
随机推荐
- iOS 开发小技巧
1.Xcode配置 1.1> 安装Alcatraz包管理器 打开Terminal终端命令行 curl -fsSL https://raw.github.com/supermarin/Alcatr ...
- GDI+学问------ 绘制可变角度的色彩渐变效果
GDI+ 它是GDI(Windows 图形设备接口提供的早期版本)也许是版本号,它是Microsoft Windows XP作系统即兴许版本号的图形显示技术. 它已经集成到了.Net开发环境中.所以无 ...
- Swift语言指南(五)--数字字面量和数字类型转换
原文:Swift语言指南(五)--数字字面量和数字类型转换 数字字面量 整数字面量写法如下: · 十进制数,无前缀 · 二进制数,以 0b 为前缀 · 八进制数,以 0o 为前缀 · 十六进制数,以 ...
- Oracle 11g password过期被锁定报道 ORA-28000 the account is locked
一.触发这个错误的原因及相关因素 是因为oracle11g中默认在default概要文件里设置了"PASSWORD_LIFE_TIME=180天"所导致.在Oracle 11g中是 ...
- Hadoop-2.4.1学习之Writable及事实上现
Hadoop基于DataInput和DataOutput实现了简单.高效的序列化协议,而Writable接口定义了Hadoop序列化的方法,MapReduce框架中的不论什么键值类型都实现了该接口,比 ...
- ASP.NET学习笔记2--自己写代码绑定Gridview
像以前一样,先写好自己的样式布局, 第二步,在数据库建立一个商品表 代码如下: CREATE TABLE [SHANGPING_INFO] ( [Shangping_Id] INT PRIMARY K ...
- JavaScript两种方法来定义一个函数
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- <C++ 实现设计模式> 观察者模式
观察者模式,又称公布--订阅,mvc模式等. 通俗点讲,比方股票来说,非常多人关注一支股票,派一个人去观察股票的情况,一有变化(观察),就通知全部的预定这个消息的人. 而我们常见的mvc模式,v是指v ...
- 解决IIS7运行ASP提示错误:An error occurred on the server when processing the URL. Please contact the system administrator
原文:解决IIS7运行ASP提示错误:An error occurred on the server when processing the URL. Please contact the syste ...
- iOS7 UIKit动力学-碰撞特性UICollisionBehavior 上
我们谈到了重力上述财产UIGravityBehavior这个类. 非常明确的看法,当我们添加的属性的严重性后,,苹果UIview像掉进无底洞,地下坠,不断的加速.而如今呢,我们要在这个手机屏幕上,加入 ...