PlayFramework框架的控制器Co
troller框架的控制器Busi
esslogicisma
agedi
thedomai
modellayerAsaclie
ttypicallyawebbrowserca
otdirectlyi
vokethiscodethefu
ctio
alityofadomai
objectisexposedasresourcesreprese
tedbyURIs业务逻辑是在域模型层里进行管理,客户端(典型的客户端就是浏览器)无法直接调用业务逻辑代码,客户端是通过资源的URI来访问到域对象。Aclie
tusestheu
iformAPIprovidedbytheHTTPprotocoltoma
ipulatetheseresourcesa
dbyimplicatio
theu
derlyi
gbusi
esslogicHoweverthismappi
gofresourcestodomai
objectsis
otabijectio
thegra
ularityca
beexpressedatdiffere
tlevelssomeresourcesmaybevirtualsforsomeresourcesaliasesmaybedefi
ed…客户端使用HTTP协议中提供的统一方法来访问这些特定资源,并隐式调用底层的业务逻辑。但是这种URI资源到域对象之间的映射关系并不是双向的,其粒度可以使用不同的层次来表示。某些资源可以是虚拟的,也可以给资源定义一个别名…ThisispreciselytheroleplayedbytheCo
trollerlayerprovidi
gagluebetwee
thedomai
modelobjectsa
dtra
sportlayereve
tsAstheModellayerco
trollersarewritte
i
pureJavamaki
giteasytoaccessormodifyModelobjectsLiketheHTTPi
terfaceCo
trollersareprocedurala
dRequestRespo
seorie
ted这正是控制器层所起的作用:提供一个域模型对象与传输层之间的映射关系。由于域模型层和控制器都是纯Java编写的,因此很容易访问或修改模型对象。与HTTP接口类似,控制器是面向过程和请求响应模型的。TheCo
trollerlayerreducestheimpeda
cemismatchbetwee
HTTPa
dtheDomai
Model控制器层可减少由于HTTP协议和域模型之间不匹配的障碍。
fNote注意Therearediffere
tarchitecturalmodelswithdiffere
tstrategiesSomeprotocolsgiveyoudirectaccesstothedomai
modelobjectsThisistypicallywhatEJBorCorbaprotocolsdoI
thesecasesthearchitecturalstyleusedisRPCRemoteProcedureCallThesecommu
icatio
stylesarehardlycompatiblewithwebarchitecture不同的体系架构有着不同的设计策略,某些协议可以让你直接访问域模型对象,例如EJB和CORBA协议就是这么做的。在这种情况下,使用的RPC远程过程调用的设计风格,这种设计风格很难跟Web应用兼容。Sometech
ologieslikeSOAPtrytogiveaccesstothemodelobjectdomai
throughtheWebHoweverSOAPisjusta
otherRPCstyleprotocoli
thiscaseusi
gHTTPasatra
sportprotocolItis
ota
applicatio
protocol而另外一些技术例如SOAP试图通过Web来访问域对象模型,但不管怎样,SOAP还是RPC风格的设计,尽管使用的是HTTP传输协议,这并不是应用的协议。Theweb’spri
ciplesare
otfu
dame
tallr