MVCS - 模型视图控制器服务 [英] MVCS - Model View Controller Service

查看:31
本文介绍了MVCS - 模型视图控制器服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 MVC 很长时间了,听说过服务"层(例如在 Java 网络项目中),我一直想知道这是否是一个真实的架构模式,因为我找不到很多关于它的信息.

I've been using MVC for a long time and heard about the "Service" layer (for example in Java web project) and I've been wondering if that is a real architectural pattern given I can't find a lot of information about it.

MVCS 的思想是在控制器和模型之间有一个服务层,来封装控制器中可能存在的所有业务逻辑.这样,控制器就可以转发和控制执行.并且您可以在多个控制器(例如,网站和网络服务)中调用 Service,而无需重复代码.

The idea of MVCS is to have a Service layer between the controller and the model, to encapsulate all the business logic that could be in the controller. That way, the controllers are just there to forward and control the execution. And you can call a Service in many controllers (for example, a website and a webservice), without duplicating code.

推荐答案

服务层可以有多种解释,但它通常是您拥有核心业务处理逻辑的地方,位于您的 MVC 架构之下,但在您的架构之上数据访问架构.

The service layer can be interpreted a lot of ways, but it's usually where you have your core business processing logic, and sits below your MVC architecture, but above your data access architecture.

例如,一个完整系统的层可能如下所示:

For example, you layer of a complete system may look like this:

  1. 视图层:您的 MVC 框架 &选择代码
  2. 服务层:您的控制器将调用该层的对象来获取或更新模型或其他请求.
  3. 数据访问对象:这些是您的服务层将调用以获取/更新所需数据的抽象.这一层通常会调用数据库或其他一些系统(例如:LDAP 服务器、Web 服务或 NoSql 类型的数据库)

服务层将负责:

  • 从各种数据源(或数据访问对象)中检索和创建您的模型".
  • 更新各种存储库/资源中的值.
  • 执行特定于应用程序的逻辑和操作等.

您在 MVC 中使用的模型可能来自也可能不来自您的服务.您可能希望获取您的服务给您的结果,并将它们处理成一个更适合您的媒体(例如:网页)的模型.

The Model you use in your MVC may or may not come from your services. You may want to take the results your service gives you and manipulate them into a model that's more specific to your medium (eg: a web page).

这篇关于MVCS - 模型视图控制器服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆