DDD:四色原型中Role的 “六” 种实现方式和PHP的Swoole扩展
目录
背景六种实现方式第一种:未显式体现角色的模式。第二种:使用“显式接口”显式体现角色的模式。第三种:使用“扩张方法”显式体现角色的模式。第四种:使用“领域服务”显式体现角色的模式。第五种:使用“包装类型”显式体现角色的模式。第六种:使用“动态代理”显式体现角色的模式。如何设计Context?备注
背景返回目录
一个实体在不同的上下文中具备不同的职责,如:产品在“生产完成上下文”中具备的一些职责,在“质检相关上下文”中具备另外一些职责。四色原型、DIC和“UML事物模式”在不同的维度阐述了这一情况,在代码层面到底该如何表达呢?本文给出了一些思路。
六种实现方式返回目录
因为:MI(Manufacture和QualityTesting)和Context(ManufactureContext、QualityTestingBeginningContext和QualityTestingCompletingContext)都是空实现且每种风格中的代码都一样,后面只给出跟PPT和Role相关的代码。
第一种:未显式体现角色的模式。返回目录
类图

代码

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.V1
8 {
9 class Product
10 {
11 public void CompleteManufacture(ManufactureContext context) { }
12
13 public void BeginQualityTesting(QualityTestingBeginningContext context) { }
14
15 public void CompleteQualityTesting(QualityTestingCompletingContext context) { }
16 }
17 }

第二种:使用“显式接口”显式体现角色的模式。返回目录
类图

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace DCIStudy.V2
{
interface IManufactureProduct
{
void CompleteManufacture(ManufactureContext context);
}
} using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace DCIStudy.V2
{
interface IQualityTestingProduct
{
void BeginQualityTesting(QualityTestingBeginningContext context); void CompleteQualityTesting(QualityTestingCompletingContext context);
}
} using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace DCIStudy.V2
{
class Product : IManufactureProduct, IQualityTestingProduct
{
void IManufactureProduct.CompleteManufacture(ManufactureContext context) { } void IQualityTestingProduct.BeginQualityTesting(QualityTestingBeginningContext context) { } void IQualityTestingProduct.CompleteQualityTesting(QualityTestingCompletingContext 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.V3
8 {
9 static class ManufactureProductExtentions
10 {
11 public static void CompleteManufacture(this Product that, ManufactureContext context) { }
12 }
13 }
14
15 using System;
16 using System.Collections.Generic;
17 using System.Linq;
18 using System.Text;
19 using System.Threading.Tasks;
20
21 namespace DCIStudy.V3
22 {
23 static class QualityTestingProductExtentions
24 {
25 public static void BeginQualityTesting(Product that, QualityTestingBeginningContext context) { }
26
27 public static void CompleteQualityTesting(Product that, QualityTestingCompletingContext context) { }
28 }
29 }

第四种:使用“领域服务”显式体现角色的模式。返回目录
类图

代码

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.V4
8 {
9 class ManufactureProductService
10 {
11 public void CompleteManufacture(Product product, ManufactureContext context) { }
12 }
13 }
14
15 using System;
16 using System.Collections.Generic;
17 using System.Linq;
18 using System.Text;
19 using System.Threading.Tasks;
20
21 namespace DCIStudy.V4
22 {
23 class QualityTestingProductService
24 {
25 public void BeginQualityTesting(Product product, QualityTestingBeginningContext context) { }
26
27 public void CompleteQualityTesting(Product product, QualityTestingCompletingContext context) { }
28 }
29 }

第五种:使用“包装类型”显式体现角色的模式。返回目录
类图

代码

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.V5
8 {
9 class ManufactureProduct
10 {
11 private Product _product;
12
13 public ManufactureProduct(Product product)
14 {
15 _product = product;
16 }
17
18 public void CompleteManufacture(ManufactureContext context) { }
19 }
20 }
21
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Text;
26 using System.Threading.Tasks;
27
28 namespace DCIStudy.V5
29 {
30 class QualityTestingProduct
31 {
32 private Product _product;
33
34 public QualityTestingProduct(Product product)
35 {
36 _product = product;
37 }
38
39 public void BeginQualityTesting(QualityTestingBeginningContext context) { }
40
41 public void CompleteQualityTesting(QualityTestingCompletingContext context) { }
42 }
43 }

第六种:使用“动态代理”显式体现角色的模式。返回目录
时间不够了,这种实现方式需要独立写一篇文章。
如何设计Context?返回目录
PPT对应的Role会参与到一个到多个Context中,一般来说一个Context涉及一个MI,如果MI为“Moment”,多数情况需要一个Context,如果MI为“Interval”,多数情况需要两个Context,根据MI的业务生命周期不同,所需的Context也不同。
备注返回目录
仓促写完,还没有具体深入分析如何做出不同的选择和折中,群里有朋友实战过,有机会再写一篇这样的文章。
Node.js的颠覆者:PHP的Swoole扩展
PHP对比Node.js的优势:
1、PHP开发效率更高
2、PHP程序员更多
3、PHP开源项目多
Swoole对比Node.js的优势:
1、swoole是原生支持多进程/多线程的
2、swoole使用消息传递+多Worker进程,而不是多线程+共享内存+加锁
3、swoole的代码编写是同步,而不是嵌套异步回调
4、swoole内置了Node.js所没有的额外特性
Swoole项目地址:
DDD:四色原型中Role的 “六” 种实现方式和PHP的Swoole扩展的更多相关文章
- DDD:四色原型中Role的 “六” 种实现方式
背景 一个实体在不同的上下文中具备不同的职责,如:产品在“生产完成上下文”中具备的一些职责,在“质检相关上下文”中具备另外一些职责.四色原型.DIC和“UML事物模式”在不同的维度阐述了这一情况,在代 ...
- .NET应用架构设计—面向对象分析与设计四色原型模式(彩色建模、领域无关模型)(概念版)
阅读目录: 1.背景介绍 2.问自己,UML对你来说有意义吗?它帮助过你对系统进行分析.建模吗? 3.一直以来其实我们被一个缝隙隔开了,使我们对OOAD遥不可及 4.四色原型模式填补这个历史缝隙,让我 ...
- .NET应用架构设计—四色原型模式(色彩造型、域无关的模型)(概念版)
阅读文件夹: 1.背景介绍 2.问自己,UML对你来说有意义吗?它帮助过你对系统进行分析.建模吗? 3.一直以来事实上我们被一个缝隙隔开了,使我们对OOAD遥不可及 4.四色原型模式填补这个历史缝隙, ...
- JAVA高级架构师基础功:Spring中AOP的两种代理方式:动态代理和CGLIB详解
在spring框架中使用了两种代理方式: 1.JDK自带的动态代理. 2.Spring框架自己提供的CGLIB的方式. 这两种也是Spring框架核心AOP的基础. 在详细讲解上述提到的动态代理和CG ...
- spring 整合 mybatis 中数据源的几种配置方式
因为spring 整合mybatis的过程中, 有好几种整合方式,尤其是数据源那块,经常看到不一样的配置方式,总感觉有点乱,所以今天有空总结下. 一.采用org.mybatis.spring.mapp ...
- Django中提供的6种缓存方式
由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用: 缓存,缓存将一个某个views的返回值保存至内存或者memcache中, ...
- Springboot中IDE支持两种打包方式,即jar包和war包
Springboot中IDE支持两种打包方式,即jar包和war包 打包之前修改pom.xml中的packaging节点,改为jar或者war 在项目的根目录执行maven 命令clean pa ...
- Vue中常用的几种传值方式
Vue中常用的几种传值方式 1. 父传子 父传子的实现方式就是通过props属性,子组件通过props属性接收从父组件传过来的值,而父组件传值的时候使用 v-bind 将子组件中预留的变量名绑定为da ...
- Android中BroadcastReceiver的两种注册方式(静态和动态)详解
今天我们一起来探讨下安卓中BroadcastReceiver组件以及详细分析下它的两种注册方式. BroadcastReceiver也就是"广播接收者"的意思,顾名思义,它就是用来 ...
随机推荐
- Mac+PhpStorm+XAMPP+Xdebug
Mac+PhpStorm+XAMPP+Xdebug 环境的配置 在上一篇 PHP 系列的文章<PHP 集成开发环境比较>中,我根据自己的亲身体验,非常简略的介绍和对比了几款常用的集成开 ...
- 在Windows系统中安装集成的PHP开发环境
原文:在Windows系统中安装集成的PHP开发环境 刚想学php的,又不会配置复杂php的环境,可以使用集成的,目前网上提供常用的PHP集成环境主要有AppServ.phpStudy.WAMP和XA ...
- 宏观CMS-->功能体系结构内容管理系统
CMS,Content Management System,一个非常普通的站点内容管理系统.本文章旨在从一定的高度把CMS的功能概念做一个分解论述 ,希望读者能够有所感. 1.前台 前台是站点中给 ...
- 虚拟局域网(VLAN)组态
图1 实验拓扑图 实验内容: (一)分别把交换机命名为SWA,SWB. (二)划分虚拟局域网vlan,并静态地把port划分到valn中. 第一.使用两种方法划分vlan. l 在全局模式下划分vl ...
- 【Java&Android开源库代码分析】のandroid-async-http の开盘
在<[Java&Android开源库代码剖析]のandroid-smart-image-view>一文中我们提到了android-async-http这个开源库,本文正 ...
- SQL点滴21—几个有点偏的语句
原文:SQL点滴21-几个有点偏的语句 SQL语句是一种集合操作,就是批量操作,它的速度要比其他的语言快,所以在设计的时候很多的逻辑都会放在sql语句或者存储过程中来实现,这个是一种设计思想.但是今天 ...
- 《Visual Studio Magazine》2013年读者选择奖—界面框架类
好消息!2013 Visual Studio Magazine读者选择奖已经正式揭晓了!据了解,截至今年此奖项已经评选了21次,非常值得.NET开发人员信赖和参考.此次评选共有400多个产品角逐28个 ...
- 淘宝code
淘宝code 相信大家都听说过GitHub,也有很多人在用,但是GitHub毕竟在国外,速度不是很给力,而且安装过程也是很漫长.今天来给大家介绍一个国内的免费的开源项目平台,当然也是一个SVN版本控制 ...
- Objective C多态
面向对象的封装的三个基本特征是.继承和多态. 包是一组简单的数据结构和定义相关的操作在上面的其合并成一个类,继承1种亲子关系,子类能够拥有父类定的成员变量.属性以及方法. 多态就是指父类中定义的成员变 ...
- android 使用 service 实现音乐
今天的球员趁service.播放音乐service结束,进度条activity结束,因此,基础工作activity和service互动,本文将使用IBinder互动.主要activity能够调用ser ...