欢迎来到天天文库
浏览记录
ID:34141270
大小:3.65 MB
页数:69页
时间:2019-03-03
《2014-07-22-OSCON-Creating-Models-16x9.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、CreatingModelsRobAllen,July2014Haveyoureadthese?ThebusinesslogicisthehardpartThemodelisthesolutiontoaproblemAfantasticsolution!What’sinthemodel?What’sinthemodel?DomainPersistenceApplicationThedomainAproblemAcustomerwantstoplanajourneybetweentwostations.!Howdowem
2、odelthis?Identifythekeyobjects•Customer!•Journey!•Station!•LineEntity–relationshipdiagramEntitiesrepresentthingsintheproblem-spaceEntity•Meanssomethingtothecustomer!•Anobjectdefinedprimarilybyitsidentity!•Mutable!•Persisted!•HasalifecycleIdentity•Theidentityofano
3、bjectiswhatitmeanstothecustomer!•UniquewithinthescopeofthedomainForatubestation,thisisit’sname,notitsdatabaseid.Valueobjects•Definedprimarilybyitsattributes!•Immutable!•Simple!!•DonotexistwithoutanentityAstationhasalocationAstationhasalocationDomainservicesIfaSER
4、VICEweredevisedtomakeappropriatedebitsandcreditsforafundstransfer,thatcapabilitywouldbelonginthedomainlayer.–EricEvansDomainservices•Wemapthebusinessprocessestoservices!•Representsbehaviourinthedomain!•Aservicedoesnothaveinternalstate!•Usuallyapointofconnectionf
5、ormanyobjectsLet’slookatsomecodeSomecodeclassJourney{functiongetStart(){}functionsetStart(Station$start){}functiongetStop(){}functionsetStop(Station$stop){}functionsetRoute(){}functiongetRoute(){}}classRoutingService{functionroute(Station$start,Station$stop){}}S
6、omecodeclassJourney{functiongetStart(){}functionsetStart(Station$start){}functiongetStop(){}functionsetStop(Station$stop){}functionsetRoute(){}functiongetRoute(){}}classRoutingService{functionroute(Station$start,Station$stop){}}SomecodeclassJourney{functiongetSt
7、art(){}functionsetStart(Station$start){}functiongetStop(){}functionsetStop(Station$stop){}functionsetRoute(){}functiongetRoute(){}}classRoutingService{functionroute(Station$start,Station$stop){}}AnaemicdomainmodelYourealizethatthereishardlyanybehaviorontheseobje
8、cts,makingthemlittlemorethanbagsofgettersandsetters.!!Insteadthereareasetofserviceobjectswhichcaptureallthedomainlogic.–MartinFowlerEntitywithbehaviourclassJourney{fu
此文档下载收益归作者所有
点击更多查看相关文章~~