荣耀彩票代理

  • 热门专题

浅谈我对DDD领域驱动设计的理解

作者:netfocus  发布日期:2016-06-08 00:06:10
  • 从遇到问题开始

    DANGRENMENYAOZUOYIGERUANJIANXITONGSHI,YIBANZONGSHIYINWEIYUDAOLESHENMEWENTI,RANHOUXIWANGTONGGUOYIGERUANJIANXITONGLAIJIEJUE。

    BIRU,WOSHIYIJIAQIYE,RANHOUWOJUEDEWOXIANZAIXIANXIAXIAOSHOUZIJIDECHANPINHAIBUGOU,WOXIWANGNENGGOUZAIXIANSHANGYENENGXIAOSHOUZIJIDECHANPIN。SUOYI,ZIRANERRANJIUXIANGDAOYAOZUOYIGEPUTONGDIANSHANGXITONG,YONGYUSHIXIANZAIXIANXIAOSHOUZIJIQIYECHANPINDEMUDE。

    再比如,我是一家互联网荣耀彩票代理公司,公司有很多系统对外提供服务,面向很多客户端设备。但是最近由于各种原因,导致服务经常出故障。所以,我们希望通过各种措施提高服务的质量和稳定性。其中的一个措施就是希望能做一个灰度发布的平台,这个平台可以提供灰度发布的服务。然后,当某个业务系统做了一些修改并需要发布时,可以使用我们的灰度发布平台来非常方便的实现灰度发布的功能。比如在灰度发布平台上方便的定制允许哪些特定的客户端才会访问新服务,哪些客户端继续使用老服务。灰度发布平台可以提供各种灰度的策略。有了这样的灰度发布机制,那即便系统的新逻辑有什么问题,受影响的面也不会很大,在可控范围内。所以,如果公司里的所有对外提供服务的系统都接入了灰度平台,那这些系统的发布环节就可以更加有保障了。

    ZONGZHI,WOMENZUORENHEYIGERUANJIANXITONG,DOUSHIYOUYUANYINDE,FOUZEJIUMEIBIYAOZUOZHEIGEXITONG,ERZHEIGEYUANYINJIUSHIWOMENYUDAODEWENTI。SUOYI,TONGGUOWENTI,WOMENJIUZHIDAOLEWOMENXUYAOYIGESHENMEYANGDEXITONG,ZHEIGEXITONGJIEJUESHENMEYANGDEWENTI。ZUIHOU,WOMENJIUHENZIRANDEDECHULEYIGEMUBIAO,JIZHIDAOLEZIJIYAOSHENME。BIRUWOYAOZUOYIGELUNTAN、YIGEBOKEXITONG、YIGEDIANSHANGPINGTAI、YIGEHUIDUFABUXITONG、YIGEIDE、YIGEFENBUSHIXIAOXIDUILIE、YIGETONGXINKUANGJIA,DENGDENG。

    DDD切入点1 - 理解概念

    荣耀彩票代理DDDDEQUANCHENGWEIDomain-driven Design,JILINGYUQUDONGSHEJI。XIAMIANWOCONGLINGYU、WENTIYU、LINGYUMOXING、SHEJI、QUDONGZHEIJIGECIYUDEHANYIHELIANXIDEJIAODUQUCHANSHUDDDSHIRUHERONGRUDAOWOMENPINGSHIDERUANJIANKAIFACHUQIJIEDUANDE。YAOLIJIESHENMESHILINGYUQUDONGSHEJI,SHOUXIANYAOLIJIESHENMESHILINGYU,SHENMESHISHEJI,HAIYOUQUDONGSHISHENMEYISI,SHENMEQUDONGSHENME。

    什么是领域(Domain)?

    QIANMIANWOMENYIJINGQINGCHUDEZHIDAOWOMENXIANZAIYAOZUOYIGESHENMEYANGDEXITONG,ZHEIGEXITONGXUYAOJIEJUESHENMEWENTI。WORENWEIRENHEYIGEXITONGDOUHUISHUYUMOUGETEDINGDELINGYU,BIRULUNTANSHIYIGELINGYU,ZHIYAONIXIANGZUOYIGELUNTAN,NEIZHEIGELUNTANDEHEXINYEWUSHIQUEDINGDE,BIRUDOUYOUYONGHUFATIE、HUITIEDENGHEXINJIBENGONGNENG。BIRUDIANSHANGPINGTAI、PUTONGDIANSHANGXITONG,ZHEIZHONGDOUSHUYUWANGSHANGDIANSHANGLINGYU,ZHIYAOSHIZHEIGELINGYUDEXITONG,NEIDOUYOUSHANGPINLIULAN、GOUWUCHE、XIADAN、JIANKUCUN、FUKUANJIAOYIDENGHEXINHUANJIE。SUOYI,TONGYIGELINGYUDEXITONGDOUJUYOUXIANGTONGDEHEXINYEWU,YINWEITAMENYAOJIEJUEDEWENTIDEBENZHISHILEISIDE。

    YINCI,WOMENKEYITUIDUANCHU,YIGELINGYUBENZHISHANGKEYILIJIEWEIJIUSHIYIGEWENTIYU,ZHIYAOSHITONGYIGELINGYU,NEIWENTIYUJIUXIANGTONG。SUOYI,ZHIYAOWOMENQUEDINGLEXITONGSUOSHUDELINGYU,NEIZHEIGEXITONGDEHEXINYEWU,JIYAOJIEJUEDEGUANJIANWENTI、WENTIDEFANWEIBIANJIEJIUJIBENQUEDINGLE。TONGCHANGWOMENSHUO,YAOCHENGWEIYIGELINGYUDEZHUANJIA,BIXUYAOZAIZHEIGELINGYUSHENRUYANJIUHENDUONIANCAIXING。YINWEIZHIYOUNIYANJIULEHENDUONIAN,NICAIHUIYUDAOFEICHANGDUODEGAILINGYUDEWENTI,TONGSHINIJIEJUEZHEIGELINGYUZHONGDEWENTIDEJINGYANYEFEICHANGFENGFU。HENDUOSHIHOU,LINGYUZHUANJIABIJISHUZHUANJIAGENGJIACHIXIANG,BIRUJINRONGLINGYUDEZHUANJIA。

    什么是设计(Design)?

    DDDZHONGDESHEJIZHUYAOZHILINGYUMOXINGDESHEJI。WEISHENMESHILINGYUMOXINGDESHEJIERBUSHIJIAGOUSHEJIHUOQITADESHENMESHEJINI?YINWEIDDDSHIYIZHONGJIYUMOXINGQUDONGKAIFADERUANJIANKAIFASIXIANG,QIANGDIAOLINGYUMOXINGSHIZHENGGEXITONGDEHEXIN,LINGYUMOXINGYESHIZHENGGEXITONGDEHEXINJIAZHISUOZAI。MEIYIGELINGYU,DOUYOUYIGEDUIYINGDELINGYUMOXING,LINGYUMOXINGNENGGOUHENHAODEBANGWOMENJIEJUEFUZADEYEWUWENTI。

    荣耀彩票代理CONGLINGYUHEDAIMASHIXIANDEJIAODULAILIJIE,LINGYUMOXINGBANGDINGLELINGYUHEDAIMASHIXIAN,QUEBAOLEZUIZHONGDEDAIMASHIXIANJIUYIDINGSHIJIEJUELELINGYUZHONGDEHEXINWENTIDE。YINWEI:1)LINGYUQUDONGLINGYUMOXINGSHEJI;2)LINGYUMOXINGQUDONGDAIMASHIXIAN。WOMENZHIYAOBAOZHENGLINGYUMOXINGDESHEJISHIZHENGQUEDE,JIUNENGQUEDINGLINGYUMOXINGKEYIJIEJUELINGYUZHONGDEHEXINWENTI;TONGLI,WOMENZHIYAOBAOZHENGDAIMASHIXIANSHIYANGEANZHAOLINGYUMOXINGDEYITULAILUODIDE,NEIJIUNENGBAOZHENGZUIHOUCHULAIDEDAIMANENGGOUJIEJUELINGYUDEHEXINWENTIDE。ZHEIGESILU,HECHUANTONGDEFENXI、SHEJI、BIANMAZHEIJIGEJIEDUANBEIGELIE(BINGQIEMEIGEJIEDUANDECHANWUYEBUTONG)DERUANJIANKAIFAFANGFAXUEXINGCHENGXIANMINGDEDUIBI。

    什么是驱动(Driven)?

    荣耀彩票代理SHANGMIANQISHIYIJINGTIDAOLE,JIUSHI:1)LINGYUQUDONGLINGYUMOXINGSHEJI;2)LINGYUMOXINGQUDONGDAIMASHIXIAN。ZHEIGEJIUHEWOMENCHUANTONGDESHUJUKUQUDONGKAIFADESILUXINGCHENGDUIBILE。DDDZHONG,WOMENZONGSHIYILINGYUWEIBIANJIE,FENXILINGYUZHONGDEHEXINWENTI(HEXINGUANZHUDIAN),RANHOUSHEJIDUIYINGDELINGYUMOXING,ZAITONGGUOLINGYUMOXINGQUDONGDAIMASHIXIAN。ERXIANGSHUJUKUSHEJI、CHIJIUHUAJISHUDENGZHEIXIEDOUBUSHIDDDDEHEXIN,ERSHIWAIWEIDEDONGXI。

    领域驱动设计(DDD)告诉我们的最大价值我觉得是:当我们要开发一个系统时,应该尽量先把领域模型想清楚,然后再开始动手编码,这样的系统后期才会很好维护。但是,很多项目(尤其是互联网项目,为了赶工)都是一开始模型没想清楚,一上来就开始建表写代码,代码写的非常冗余,完全是过程是的思考方式,最后导致系统非常难以维护。而且更糟糕的是,出来混总是要还的,前期的领域模型设计的不好,不够抽象,如果你的系统会长期需要维护和适应业务变化,那后面你一定会遇到各种问题维护上的困难,比如数据结构设计不合理,代码到处冗余,改BUG到处引入新的BUG,新人对这种代码上手困难,等。而那时如果你再想重构模型,那要付出的代价会比一开始重新开发还要大,因为你还要考虑兼容历史的数据,数据迁移,如何平滑发布等各种头疼的问题。所以,就导致我们最后天天加班。

    荣耀彩票代理SUIRAN,WOMENDOUZHIDAOZHEIGEDAOLI,DANSHIWOYEMINGBAI,RENDEXIGUANHENNANGAIBIANDE,DABUFENRENDOUHENNANCONGMIANXIANGGUOCHENGSHIDEXIANGDAONALIXIEDAONALIDESIXIANGZHUANBIANWEIJIYUXITONGHUADEMOXINGQUDONGDESIWEI。WOXIANG,ZHEIHUOXUSHIDDDHENNANZAIZHONGGUOHUOGUOWAILIUXINGQILAIDEYUANYINBA。DANSHI,WOXIANGZHEIBUYINGGAICHENGWEIWOMENFANGQIXUEXIDDDDEYUANYIN,DUIBA!

    概念总结:

    领域就是问题域,有边界,领域中有很多问题; 任何一个系统要解决的那个大问题都对应一个领域; 通过建立领域模型来解决领域中的核心问题,模型驱动的思想; 领域建模的目标针对我们在领域中所关心的问题,即只针对核心关注点,而不是整个领域中的所有问题; 领域模型在设计时应考虑一定的抽象性、通用性,以及复用价值; 通过领域模型驱动代码的实现,确保代码让领域模型落地,代码最终能解决问题; 领域模型是系统的核心,是领域内的业务的直接沉淀,具有非常大的业务价值; 技术架构设计或数据存储等是在领域模型的外围,帮助领域模型进行落地;

    DDD切入点2 - 理解领域、拆分领域、细化领域

    理解领域知识是基础

    SHANGMIANWOMENTONGGUODIYIBU,SUIRANWOMENMINGQUELEYAOZUOYIGESHENMEYANGDEXITONG,GAIXITONGZHUYAOJIEJUESHENMEWENTI,DANSHIJIUZHEIYANGWOMENHAIWUFAKAISHIJINXINGSHIJIDEXUQIUFENXIHEMOXINGSHEJI,WOMENHAIBIXUJIANGWOMENDEWENTIJINXINGCHAIFEN,XUQIUJINXINGXIHUA。YOUXIESHIHOU,XUQIUFANG,JITICHUWENTIDEREN,HENKENENGZIJIBUQINGCHUJUTIXIANGYAOSHENME。TAZHIZHIDAOYIGEGAINIAN,YIGEDADEMUBIAO。BIRUTAZHIZHIDAOYAOZUOYIGEGUPIAOJIAOYIXITONG,YIGEHUIDUFABUXITONG,YIGEDIANSHANGPINGTAI,YIGEKAIFAGONGJU,DENG。DANSHITABUQINGCHUZHEIXIEXITONGYINGGAIJUTIZUOCHENGSHENMEYANGZI。ZHEIGESHIHOU,WORENWEILINGYUZHUANJIAJIUFEICHANGZHONGYAOLE,DDDYEFEICHANGQIANGDIAOLINGYUZHUANJIADEZHONGYAOXING。YINWEILINGYUZHUANJIADUIZHEIGELINGYUFEICHANGLEJIE,DUILINGYUNEIDEGEZHONGYEWUCHANGJINGHEGEZHONGYEWUGUIZEYEFEICHANGQINGCHU,ZONGZHI,DUIZHEIGELINGYUNEIDEYIQIEYEWUXIANGGUANDEZHISHIDOUFEICHANGLEJIE。SUOYI,TAMENZIRANJIUYOUNENGLIBIAODACHUXITONGGAIZUOCHENGSHENMEYANGZI。SUOYI,YAOZHIDAOYIGEXITONGDAODIGAIZUOCHENGSHENMEYANGZI,DAODINAXIESHIHEXINYEWUGUANZHUDIAN,ZHINENGKAOCHENDIANLINGYUNEIDEGEZHONGZHISHI,BIEWUTAFA。YINCI,JIASHENIXIANZAIDASUANZUOYIGEDIANSHANGPINGTAI,DANSHINIDUIZHEIGELINGYUMEISHENMELEJIE,NEINIYIDINGDEXIANQULEJIEXIAGAILINGYUNEIZHULIUDEDIANSHANGPINGTAI,BIRUTAOBAO、TIANMAO、JINGDONG、YAMAXUNDENG。ZHEIGELEJIEDEGUOCHENGJIUSHINICHENDIANLINGYUZHISHIDEGUOCHENG。RUGUONIBULEJIE,JIUSUANNILINGYUJIANMODENENGLIZAIQIANG,GEZHONGJISHUJIAGOUNENGLIZAIQIANGYESHISHIBUSHANGLI。LINGYUZHUANJIABUSHIMOUGEGUDINGDEJIAOSE,ERSHIMOUYILEIREN,ZHEILEIRENDUIZHEIGELINGYUFEICHANGLEJIE。BIRU,YIGEKAIFARENYUANYEKEYISHIYIGELINGYUZHUANJIA。JIASHENIZAIYIGEGONGSIKAIFAHEWEIHUYIGEXITONGYIJINGHAOJINIANLE,DANSHIZHEIGEXITONGDECHANPINJINGLI(PD)KENENGYIJINGHUANGUOHAOJIRENLE,ZHEIZHONGQINGKUANGXIA,WOXIANGXINZHEIJIRENCHANPINJINGLIDOUMEIYOUBINIGENGSHUXIZHEIGELINGYU。

    拆分领域

    荣耀彩票代理SHANGMIANWOMENMINGBAILE,LINGYUJIANMODEJICHUSHIYAOXIANLIJIELINGYU,RANGZIJICHENGWEILINGYUZHUANJIA。RUGUOZUODAOLEZHEIDIAN,WOMENJIUDAHAOLEJIANSHIDEJICHULE。DANSHI,YOUSHIYIGELINGYUWANGWANGTAIFUZA,SHEJIDAODELINGYUGAINIAN、YEWUGUIZE、JIAOHULIUCHENGTAIDUO,DAOZHIWOMENMEIBANFAZHIJIEZHENDUIZHEIGEDADELINGYUJINXINGLINGYUJIANMO。SUOYI,WOMENXUYAOJIANGLINGYUJINXINGCHAIFEN,BENZHISHANGJIUSHIBADAWENTICHAIFENWEIXIAOWENTI,RANHOUGEGEJIPODESILU。RANHOUJIRANBAYIGEDADELINGYUHUAFENWEILEDUOGEXIAODELINGYU(ZIYU),NEIZUIGUANJIANDEJIUSHIYAOLIQINGMEIGEZIYUDEBIANJIE;RANHOUYAOGAOQINGCHUNAXIEZIYUSHIHEXINZIYU,NAXIESHIFEIHEXINZIYU,NAXIESHIGONGGONGZHICHENGZIYU;RANHOU,HAIYAOSIKAOZIYUZHIJIANDELIANXISHISHENME。NEIME,WOMENGAIRUHEHUAFENZIYUNI?WODEGERENKANFASHICONGYEWUXIANGGUANXINGDEJIAODUQUSIKAO,YEJIUSHIWOMENPINGSHISHUODEANYEWUGONGNENGWEICHUFADIANJINXINGHUAFEN。HAISHINAJINGDIANDEDIANSHANGXITONGLAIFENXI,TONGCHANGYIGEDIANSHANGXITONGDOUHUIBAOHANHAOJIGEDAKUAI,BIRU:

    会员中心:负责用户账号登录、用户信息的管理; 商品中心:负责商品的展示、导航、维护; 订单中心:负责订单的生成和生命周期管理; 交易中心:负责交易相关的业务; 库存中心:负责维护商品的库存; 促销中心:负责各种促销活动的支持;

    荣耀彩票代理SHANGMIANZHEIXIEZHONGXINKANQILAIHENZIRAN,YINWEIDAJIADUIDIANZISHANGWUDEZHEIGELINGYUDOUYIJINGFEICHANGSHUXILE,SUOYIDOUMEISHENMEYIWEN,HAOXIANGHENZIRANDEYANGZI。SUOYI,LINGYUHUAFENSHIBUSHIJIUSHIMEISHENMETIAOZHANLENI?XIANRANBUSHI。ZHISUOYIWOMENJUEDEZIYUHUAFENHENJIANDAN,SHIYINWEIWOMENDUIZHENGGEDALINGYUFEICHANGLEJIELE。RUGUOWOMENYUDAOYIGELENGMENDELINGYU,JIUMEIBANFAZHEIMERONGYIDEQUHUAFENZIYULE。ZHEIJIUXUYAOWOMENXIANQUNULILIJIELINGYUNEIDEZHISHI。SUOYI,WOGERENCONGLAIBUXIANGXINSHENMEZIYUHUAFENDEJIQIAOSHENMEDEDONGXI,YINWEIWOJUEDEZHEIGEGONGZUOMEIYOURENHEJUEQIAOKEYISHIYONG。DANGWOMENBULEJIEYIGEDONGXIDESHIHOU,RUHEQUCHAIJIETA?DANGWOMENDUIZHENGGELINGYUYOUYIDINGDESHUXILE,LEJIELELINGYUNEIDEXIANGGUANYEWUDEBENZHIHEGUANXI,WOMENJIUZIRANERRANDENENGHUAFENCHUHELIDEZIYULE。BUGUOBINGBUSHISUOYOUDEXITONGDOUXUYAOHUAFENZIYUDE,YOUXIEXITONGZHISHIJIEJUEYIGEXIAOWENTI,ZHEIGEWENTIBUFUZA,KENENGZHIYOUYILIANGGEHEXINGAINIAN。SUOYI,ZHEIZHONGXITONGWANQUANBUXUYAOZAIHUAFENZIYU。DANBUSHIJUEDUIDE,DANGYIGELINGYU,WOMENDEGUANZHUDIANYUELAIYUEDUO,MEIGEGUANZHUDIANWOMENGUANZHUDEXINXIYUELAIYUEDUODESHIHOU,WOMENHUIBUYOUZIZHUDEQUJINYIBUDEHUAFENZIYU。BIRU,YEXUWOMENYIKAISHIJIANGSHANGPINHESHANGPINDEKUCUNDOUFANGZAISHANGPINZHONGXINLI,DANSHIHOULAIYOUYUKUCUNDEWEIHUYUELAIYUEFUZA,DAOZHIROUZAIYIQIDUIWOMENDEXITONGWEIHUDAILAIYIDINGDEKUNNANSHI,WOMENJIUHUIKAOLVJIANGLIANGZHEJINXINGCHAIFEN,ZHEIGEJIUSHISUOWEIDEYEWUCHUIZHIFENGE。

    细化子域

    TONGGUOSHANGMIANDELIANGBU,WOMENLEJIELELINGYULIDEZHISHI,YEDUILINGYUJINXINGLEZIYUHUAFEN。DANZHEIYANGHAIBUGOU,PINGZHEIXIEWOMENHAIWUFAJINXINGHOUXUDELINGYUMOXINGSHEJI。WOMENHAIBIXUZAIJINYIBUXIHUAMEIGEZIYU,JINYIBUMINGQUEMEIGEZIYUDEHEXINGUANZHUDIAN,JIXUQIUXIHUA。WOJUEDEWOMENXUYAOXIHUADEFANGMIANYOUYIXIAJIDIAN:

    梳理领域概念:梳理出领域内我们关注的概念、概念的关系,并统一交流词汇,形成统一语言; 梳理业务规则:梳理出领域内我们关注的各种业务规则,DDD中叫不变性(invariants),比如唯一性规则,余额不能小于零等; 梳理业务场景:梳理出领域内的核心业务场景,比如电商平台中的加入购物车、提交订单、发起付款等核心业务场景; 梳理业务流程:梳理出领域内的关键业务流程,比如订单处理流程,退款流程等;

    CONGSHANGMIANZHEI4GEFANGMIAN,WOMENCONGLINGYUGAINIAN、YEWUGUIZE、JIAOHUCHANGJING、YEWULIUCHENGDENGWEIDUSHULILEWOMENDAODIYAOSHENME,ZHENGLILEZHENGGEXITONGYINGGAIJUBEIDEGONGNENG。ZHEIGEGONGZUOWOJUEDESHIYIGEFEICHANGJUYOUCHUANGZAOXINGHEYOUNANDUDEGONGZUO。WOMENYIFANGMIANHUIZHUGUANDEDINGYIWOMENXIANGYAOSHENME;LINGYIFANGMIAN,WOMENHAIHUISIKAOWOMENYAODEDONGXIDEHELIXING。WORENWEIZHEIGEJIUSHICHANPINJINGLIDEGONGZUO,CHANPINJINGLIBIXUYAOFUQIZHIZE,BATADECHANPINCHONGFENSHEJIHAO,CONGGEGEFANGMIANQUKAOLV,RUHESHEJIYIGECHANPIN,CAINENGGENGHAODEJIEJUEYONGHUDEHEXINSUQIU,JILINGYUNEIDEHEXINWENTI。RUGUODUILINGYUBUGOULEJIE,RUGUOXIANGBUQINGCHUYONGHUDAODIYAOSHENME,RUGUOSIKAOWENTIBUGOUQUANMIAN,TANHESHEJICHUYIGEHELIDECHANPINNI?

    GUANYULINGYUGAINIANDESHULI,WOJUEDEKEYICAIYONGSISEYUANXINGFENXIFA,ZHEIGEFENXIFATONGGUOXITONGDEFANGFA,JIANGGAINIANHUAFENWEIBUTONGDEZHONGLEI,WEIBUTONGZHONGLEIDEGAINIANBIAOZHUBUTONGDEYANSE。RANHOUJIANGZHEIXIEGAINIANYOUJIDEZUHEQILAI,CONGERRANGWOMENKEYIQINGXIDEFENXICHUGAINIANHEGAINIANZHIJIANDEGUANXI。YOUXINGQUDETONGXUEKEYIZAIWANGSHANGSOUSUOXIASISEYUANXING。

    注意:上面我说的这四点,重点是梳理出我们要什么功能,而不是思考如何实现这些功能,如何实现是软件设计人员的职责。

    DDD切入点3 - 领域模型设计

    ZHEIBUFENNEIRONG,WOXIANGXUEXIDDDDERENDOUHENSHUXILE。DDDYUANZHUZHONGTICHULEHENDUOSHIYONGDEJIANMOGONGJU:JUHE、SHITI、ZHIDUIXIANG、GONGCHANG、CANGCHU、LINGYUFUWU、LINGYUSHIJIAN。WOMENKEYISHIYONGZHEIXIEGONGJU,LAISHEJIMEIYIGEZIYUDELINGYUMOXING。ZUIZHONGTONGGUOLINGYUMOXINGTUJIANGSHEJICHENDIANXIALAI。YAOSHIYONGZHEIXIEGONGJU,SHOUXIANJIUYAOLIJIEMEIGEGONGJUDEHANYIHESHIYONGCHANGJING。BUYAOYIWEIHENJIANDANE,BIRUJUHEDEHUAFENJIUSHIYIGEFEICHANGJUYOUYISHUDEHUO。TONGYIGEXITONG,BUTONGDERENSHEJICHULAIDEJUHESHIWANQUANBUTONGDE。ERQIEHENYOUKENENGGAOSHOUZHIJIANDEZUIHOUSHEJICHULAIDECHABIEFANERGENGDA,SHIJISHANGWORENWEISHISHIJIEGUANDEXIANGHUPENGZHUANG,HEHE。SUOYI,YAOLINGYUJIANMO,WOJUEDEMEIGERENDOUYINGGAIQUXUEXUEZHEXUEZHISHI,ZHEIYOUZHUYUWOMENGENGHAODERENSHISHIJIE,GENGHAODELIJIESHIWUDEBENZHI。

    荣耀彩票代理GUANYUZHEIXIEJIANMOGONGJUDEGAINIANHERUHEYUNYONGWOJIUBUDUOZHANKAILE,WOBOKELIYEYOUHENDUOZHEIFANGMIANDEJIESHAO。XIAMIANWOZAIJIANGYIXIAWORENWEIBIJIAOZHONGYAODEDONGXI,BIRUDAODIGAIRUHELINGYUJIANMO?BUZHOUYINGGAISHIZENMEYANGDE?

    领域建模的方法

    TONGGUOSHANGMIANWOJIESHAODEXIHUAZIYUDENEIRONG,XIANZAIZAILAITANGAIRUHELINGYUJIANMO,WOJUEDEJIUFANGBIANHENDUOLE。WODEZHUYAOFANGFASHI:

    划分好边界上下文,通常每个子域(sub domain)对应一个边界上下文(bounded context),同一个边界上下文中的概念是明确的,没有任何歧义; 在每个边界上下文中设计领域模型,具体的领域模型设计方法有很多种,如以场景为出发点的四色原型分析法,或者我早期写的这篇文章;这个步骤最核心的就是找出聚合根,并找出每个聚合根包含的信息;关于如何设计聚合,可以看一下我写的这篇文章; 画出领域模型图,圈出每个模型中的聚合边界; 设计领域模型时,要考虑该领域模型是否满足业务规则,同时还要综合考虑技术实现等问题,比如并发问题;领域模型不是概念模型,概念模型不关注技术实现,领域模型关心;所以领域模型才能直接指导编码实现; 思考领域模型是如何在业务场景中发挥作用的,以及是如何参与到业务流程的每个环节的; 场景走查,确认领域模型是否能满足领域中的业务场景和业务流程; 模型持续重构、完善、精炼;

    领域模型的核心作用:

    抽象了领域内的核心概念,并建立概念之间的关系; 领域模型承担了领域内的状态的维护; 领域模型维护了领域内的数据之间的业务规则,数据一致性;

    XIATUSHIWOZUIJINZUOGEYIGEPUTONGDIANSHANGXITONGDESHANGPINZHONGXINDELINGYUMOXINGTU,JIDAJIACANKAO:

    领域模型设计只是软件设计中的一小部分

    荣耀彩票代理XUYAOTEBIEZHUYIDESHI,LINGYUMOXINGSHEJIZHISHIZHENGGERUANJIANSHEJIZHONGDEHENXIAOYIBUFEN。CHULELINGYUMOXINGSHEJIZHIWAI,YAOLUODIYIGEXITONG,WOMENHAIYOUFEICHANGDUODEQITASHEJIYAOZUO,BIRU:

    容量规划 架构设计 数据库设计 缓存设计 框架选型 发布方案 数据迁移、同步方案 分库分表方案 回滚方案 高并发解决方案 一致性选型 性能压测方案 监控报警方案

    DENGDENG。SHANGMIANZHEIXIEDOUXUYAOWOMENPINGSHIDEDALIANGXUEXIHEJILEI。ZUOWEIYIGEHEGEDEKAIFARENYUANHUOJIAGOUSHI,WOJUEDECHULEYAOHUIDDDLINGYUQUDONGSHEJI,HAIYAOHUISHANGMIANZHEIMEDUODEJISHUNENGLI,QUESHISHIFEICHANGBURONGYIDE。SUOYI,QIANWANBUYAOYIWEIHUIDDDLEJIUYIWEIZIJIHENNIUBI,SHIJISHANGNIHUIDEZHISHIRUANJIANSHEJIZHONGDEBINGSHANYIJIAOERYI。

    总结

    BENWENDEZHONGDIANSHIJIYUWOGERENDUIDDDDEYIXIELIJIE,XIWANGNENGZHENGLICHUYIXIEZIJIZONGJIECHULAIDEYIXIEGANWUHEJINGYAN,BINGFENXIANGJIDAJIA。WOXIANGXINHENDUORENYIJINGKANGUOTAIDUODDDSHUSHANGDEDONGXI,WOZONGSHIGANJUESHUSHANGDEDONGXIKANSIDOUTAI”ZHENGGUI“,HENDUOSHIHOUWOMENDULEZHIHOUHENNANXIAOHUA,JIUSUANLIJIELESHULIDENEIRONG,DANGWOMENXIANGYAOYUNYONGDAOSHIJIANZHONGSHI,ZONGSHIGANJUEWUCONGXIASHOU。BENWENXIWANGTONGGUOTONGSUYIDONGDEWENZI,JIESHAOLEYIBUFENWODUIDDDDEXUEXIGANWUHESHIJIANXINDE,XIWANGNENGJIDAJIAYIXIEQIFAHEBANGZHU。

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规