Service layer = Application layer = GRASP Controller layer [closed]

让人想犯罪 __ 提交于 2020-01-01 05:29:08

问题


I think service/application layer is the same thing as Larman describes as GRASP Controller, being the first object beyond the GUI layer that delegates to the domain layer, and should be reusable from different GUI.

Service (Evans) layer is the same as Application (Fowler) layer because Fowler himself says so, in his "bliki" about the "Anemic Domain Model": http://martinfowler.com/bliki/AnemicDomainModel.html

Quote: "Application Layer [his name for Service Layer]: Defines the jobs the software is supposed to do and directs the expressive domain objects to work out problems. The tasks this layer is responsible for are meaningful to the business or necessary for interaction with the application layers of other systems. This layer is kept thin. It does not contain business rules or knowledge, but only coordinates tasks and delegates work to collaborations of domain objects in the next layer down. It does not have state reflecting the business situation, but it can have state that reflects the progress of a task for the user or the program."

Now consider the above description (and also see fowler's PEAA book, regarding identifying service layer methods from the use cases) and also consider the picture in Fowler's description of Service layer that illustrates the Service Layer being the first layer after the "user interface" at this URL: http://martinfowler.com/eaaCatalog/serviceLayer.html

Now compare the above mentioned Service/Application layer description with some of Larman's words about the GRASP Controller (in the 3rd edition of his best-selling OOAD book "Aplying UML and patterns", age 302-306) : "...first object beyond the UI layer that receives and coordinates ("controls") a system operation..." "...represents a use case scenario within which the system event occurs..." "... Normally, a controller should delegate to other objects the work that needs to be done; it coordinates or controls the activity. It does not do much work itself...."

I think that Larman's GRASP Controller layer is the same as Evans/Fowler's Application/Service layer. Do other people disagree ? Then please explain the significant differences between these concepts, and some example of Controller class instead of Service/Application class.

My question is born because some say that the creation of model domain objects is the responsibility of the controller, instead of the other service / application layer. But could you give me an example of service layer class and the difference between controller class?


回答1:


Actually there's UI Controller and Domain Controller as most used patterns.

UI Controller coordinates access to View, in an MVC pattern.

Domain Controller coordinates access to Domain, and it's called Service Layer (Fowler, which I prefer) or Application Layer (Evans).

Both are indirection layers (Façade Pattern), used to decouple classes between subsystems/layers. It brings modularity and better maintainability (you can swap domain for remote services or swap view from HTML to Flex, and just change the indirection layer)

GRASP Controller appears to be an hybrid of both. I recommend you to use this term only for analysis, not for implementation.

Hope it helps!



来源:https://stackoverflow.com/questions/5368085/service-layer-application-layer-grasp-controller-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!