开发者

OO application layer design question

Would it be correct to assume that a controller class is the same as a service class in the application service layer. e.g. CustomerService is the same as Custo开发者_高级运维merController


It depends on how you are defining your service layer, but in general the answer is no, they are not the same. I work with a custom MVC framework, and the Service classes are separate from the Controller classes.

The Controller classes are responsible for making application logic decisions. They decide what the application's actions should be, such as what objects get loaded and what logic gets run. Business logic, such as data changes, should not be handled by Controller classes.. they are for making decisions. In your case, CustomerController would probably decide which Customer object to load and what actions to take with it.

Service classes are generally responsible for co-ordinating interactions between business classes. Often this is in the form of some kind of data manipulation or transaction. As an example in your case, the CustomerService classes might provide methods for your Customer object to save purchases to the database or activate an RPC call on a central repository.


No, The word Controller is generally used to represent a class that is responsible for controlling the behavior or access patterns for some downstream (closer to UI) code component like the UI screen itself, or the interactions between some downstream component and an upstream compoenent that contains (or models) the data used by that downstream component.

A Service component is a component that provides some function or implements a process that is required by the applications business logic (or in some cases by infrastructure requirements or even application design requirements) that can be encapsulated in a single class to be isolated from other pieces of application functionality.


No, see model-view-controller. The controller should call the service layer to do its job, populate the model, etc. But they should not be the same thing,

  • the model represents data
  • the view renders the data
  • the controller coordinates everything, and can use the service layer.

The controller should not contain business logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜