按照“模型-视图-控制器"原理,什么是前端,什么是后端? [英] In the Model-View-Controller principle, what is the Frontend and what is the Backend?

查看:64
本文介绍了按照“模型-视图-控制器"原理,什么是前端,什么是后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维基百科说:

MVC为数据库,用户和服务器提供前端和后端. 数据处理组件.将软件系统分为 前端和后端简化了开发并分离了维护.

MVC provides front and back ends for the database, the user, and the data processing components. The separation of software systems into front and back ends simplifies development and separates maintenance.

我仍然看不到模型视图控制器原理与前端和后端之间的联系.具有访问数据库权限的模型能否被视为后端,而视图被视为前端?

I still don't see the link between the model-view-controller principle and the idea of front- and backend. Can the Model with its access to the database be seen as the Backend and the View as the frontend?

推荐答案

OK ..首先,这些术语:

OK.. first the terms:

  • 前端-是对用户可见的部分:HTML,CSS,客户端Javascript.基本上,所有这些都是前端".在桌面应用程序中,前端将是GUI.
  • 后端-是不可见部分.在Web应用程序中,这是您的Java,ruby,php或任何其他服务器端代码.它可以被解释或编译,因为它的工作方式"对它的作用"没有影响.
  • Frontend - are the parts, which are visible to users: HTML, CSS, client-side Javascript. It all is basically "frontend". In a desktop application frontend would be the GUI.
  • Backend - is the invisible part. In web applications that is your java, ruby, php or any other serverside code. It can be either interpreted or compiled, because "how" it works has no impact on "what" it is.

如果您阅读 GUI体系结构 ,并在其中研究了MVC模式,一般而言,您会了解 MVC与后端和前端的分离无关.尤其是涉及到受MVC启发的模式,我们将其用于Web应用程序.

If you read GUI Architectures and research the MVC pattern in general, you will understand that MVC is not about separation of backend and frontend. Especially when it comes to MVC-inspired patterns, that we use for web applications.

MVC和相关模式的目标是将表示与领域业务逻辑分开.

The goal of MVC and related patterns is to separate presentation from domain business logic.

这是MVC部件的基本职责:

Here are the basic responsibilities of MVC parts:

  • 模型-业务逻辑
  • 查看-演示逻辑
  • 控制器-更改模型和视图的状态(基于用户输入)
  • Model - business logic
  • View - presentation logic
  • Controller - changing state of model and view (based on user input)

让我们举个例子:

  • Twitter的替代客户端应用程序
  • 使用OAuth进行身份验证
  • 用户可以输入不同的搜索词组
  • 通过Twitter的REST API获取信息
  • 验证数据
  • 解析JSON响应
  • 操纵DOM来显示信息

这一切都可以通过客户端JavaScript来完成. 您可以让MVC triad运行前端" !同时,提供REST API的后端"是一种类似于MVC的结构.仅这次 View 生成JSON响应,而不是HTML.

This all can be done with client-side JavaScript. You can have MVC triad running "frontend"! At the same time, the "backend" which provides REST API is an MVC-like structure. Only this time the View is generating JSON responses, instead of HTML.

*结论:您可以在后端和前端使用MVC模式.**

*Conclusion: You can use MVC pattern both on backend and frontend.**

后圣经》

由于您已经使用Rails构建了一些应用程序,因此您对MVC的理解可能是一个扭曲但扭曲的事实.我之所以这样说是因为,由于RoR最初是作为原型框架(请注意所有用于生成一次性代码的脚手架和其他功能)制成的,并且由于其起源,Rails实际上正在实现最贫乏的MVP版本.

Post Scriptum

Since you have been building some applications with Rails, your understanding of MVC might be a but distorted. The reason I say this is because, since RoR was initially made as a prototyping framework (notice all the scaffolding and other features for generating throw-away code), and because of its origin, Rails is actually implementing a very anemic version of MVP.

我称其为贫血",因为它们精疲力竭都同时查看(在MVP中它应该是被动对象,而不是简单的模板)和模型层 (是的,它应该是一个复杂的层,而不是ORM实例的集合).

I call it "anemic", because they nerfed both View (it should be a passive object in MVP, not a simple template) and Model Layer (yes, it is supposed to be a complicated layer, not a collection of ORM instances).

我建议您阅读两本出版物,以更好地理解这一主题:

I would recommend for you to read two publications to get a much better grasp on the subject:

  • Patterns of Enterprise Application Architecture.. mandatory reading for serious developers
  • A Description of the Model-View-Controller User Interface Paradigm in the Smalltalk-80 System

第二个尽可能接近模式的初始定义.结合"GUI体系结构"一文,应该为您提供了扎实的基础. PoEAA书(精读,btw)将为您提供扩展它的环境.

The second one is as close as you can get to initial definition of pattern. That, together with "GUI Architectures" article, should provide you a solid footing on the subject. And the PoEAA book (hard read, btw) would give you context in which to expand it.

这篇关于按照“模型-视图-控制器"原理,什么是前端,什么是后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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