mvc2 mvc

This post is a written version of a talk given by Garann Means at LXJS and NYCjs. It has been formatted to fit your screen.

这篇文章是LXJS和NYCjs的 Garann Means 发表的演讲的书面版本。 它已经过格式化以适合您的屏幕。

There's no shortage of JavaScript MVC (Model-View-Controller) architectures out there. The best-known is Backbone, but there are others: Spine, Agility, Knockback, etc. And in addition to the range of MVC frameworks, there are MV-whatever variants. This stuff, anecdotally, is pretty popular. As of this writing, Backbone is the 7th most watched repo on GitHub. Developers love MVC.

那里不乏JavaScript MVC(模型-视图-控制器)架构。 最著名的是Backbone ,但还有其他一些: Spine , Agility , Knockback等。除了MVC框架范围之外,还有MV变体。 有趣的是,这种东西很受欢迎。 在撰写本文时,Backbone是GitHub上第七大最受欢迎的仓库。 开发人员喜欢MVC。

What makes MVC so appealing, especially for JavaScript where it's still primarily used, on the client? If you're new to application architectures, it's definitely very accessible - the model is data, the view is.. the view, and the controller makes them do stuff. Easy! If you started coding on the server-side, MVC is probably already familiar. Most Object-Oriented Programming embraces the pattern and you can find very popular MVC frameworks for Java, .NET, Python, PHP, etc. The pattern itself actually predates and was first implemented in Smalltalk, after being invented by Trygve Reenskaug in the late 70s, so its relationship with OOP has been there from the beginning. Given the unquestioned supremacy of OOP until fairly recently, it's unsurprising that MVC makes immediate sense to many of us.

是什么使MVC在客户端上如此吸引人,尤其是对于仍主要使用它JavaScript而言? 如果您是应用程序体系结构的新手,那么绝对可以轻松访问它-模型是数据,视图是..视图,控制器使它们可以完成工作。 简单! 如果您开始在服务器端进行编码,那么MVC可能已经很熟悉了。 大多数面向对象的程序设计都包含该模式,您可以找到非常流行的Java,.NET,Python,PHP等MVC框架。该模式实际上早于70年代后期由Trygve Reenskaug发明,并最初在Smalltalk中实现。 ,因此与OOP的关系从一开始就存在。 鉴于直到最近,OOP一直是至高无上的,所以MVC对我们许多人立即具有意义就不足为奇了。

JavaScript, however, is not exactly OOP. We can do OOP with it, but the two hardly go hand-in-hand. Therefore, the appropriateness of MVC varies by use case. For data entry, content management systems, and situations where we can pick out clear and obvious "models", it tends to work very nicely. But where the state of an application is more amorphous and not always tracked in the same place, in applications with lots of user interaction before any data actually changes, and in apps with very complex widgets or complex, it's less clear that it's the right choice. And if your site is JS-heavy but still static, obviously, forget it. There's no benefit in doing all that setup on a page that's going to reload and lose it all.

但是,JavaScript并不是完全面向对象的。 我们可以用它做OOP,但是两者很难并存。 因此,MVC的适用性因使用案例而异。 对于数据输入,内容管理系统以及我们可以挑选出清晰明显的“模型”的情况,它往往工作得很好。 但是,在应用程序的状态更加不确定并且不总是在同一位置进行跟踪的情况下,在实际更改任何数据之前具有大量用户交互的应用程序中,以及在具有非常复杂的小部件或复杂性的应用程序中,不清楚这是正确的选择。 而且,如果您的站点是JS密集型的,但仍然是静态的,那么显然,就算了。 在要重新加载并丢失所有内容的页面上进行所有设置没有任何好处。

The issue we run into when talking about MVC, or any other architectural pattern, is that, as web developers, these things were not created for us. We can trace the most common patterns back to Design Patterns (aka the Gang of Four book), which was published in 1995. The dawn of our field, literally. These patterns were for programmers building programs primarily for their own use, and certainly not for programmers whose work was easily revealed by going up to the menu and clicking View Source. While those patterns all made their way in some form to the back-end, that canon predates JavaScript completely.

在谈论MVC或任何其他架构模式时,我们遇到的问题是,作为Web开发人员,这些东西并不是为我们创建的。 我们可以将最常见的模式追溯到1995年出版的《 设计模式》 (又名《四人帮》一书)。 这些模式仅适用于程序员主要供自己使用的程序,而不适用于那些通过转到菜单并单击“查看源代码”即可轻松显示其工作的程序员。 尽管这些模式都以某种形式进入了后端,但该规范完全早于JavaScript。

MVC, though, was one of the few ancient methods that made immediate sense. Because it has a clear place for the UI to exist, it's easily applied to the front-end (although, again, that application is not canon). Because any pattern we want to use has to be fudged a bit to get it to fit our context, MVC is a great place to start. But it's not the only option we have.

但是,MVC是为数不多的立即可行的古老方法之一。 因为它有明确的UI放置位置,所以很容易将其应用于前端(尽管同样,该应用程序不是佳能)。 因为我们想要使用的任何模式都必须经过一些摸索才能使其适应我们的环境,所以MVC是一个很好的起点。 但这不是我们唯一的选择。

It seems fair to call Event-Driven Architectures the second most obvious pattern. We use event-driven patterns all over the place in JS, and even in combination with MV* patterns. They work well where we need a lot of messaging, and have less need for clear-cut, classical "objects". For the objects we do have, getters and setters (and soon, Object.observe()) can be used as publishers and subscribers, decoupling events, the core of the application, from the things they affect. The value, though, is that these decoupled events don't need to affect only objects, but can also affect the DOM, or server interactions, or other events, and none of that needs to be packaged up in a Model-View-Controller triad if it doesn't make sense as one.

事件驱动的体系结构称为第二最明显的模式似乎很公平。 我们在JS各处都使用事件驱动的模式,甚至与MV *模式结合使用。 它们可以在需要大量消息传递的地方很好地工作,并且对清晰,经典的“对象”的需求较少。 对于我们确实拥有的对象,可以将getter和setter(以及不久后的Object.observe() )用作发布者和订阅者,将事件(应用程序的核心)与事件的影响解耦。 不过,其价值在于,这些解耦的事件不必只影响对象,还可以影响DOM或服务器交互或其他事件,并且这些都不需要打包在Model-View-Controller中。如果没有任何意义,则使用三合会。

The Naked Objects pattern bears closest relation to MV*, and it would not be unfair to call it a variant of Presentation-Abstraction-Control (a more distant relative). This one's good for big meaty widgets that need to contain and render their own data, and whose visual representation maps directly to the data they contain. It bears similarity to the drag-and-drop IDEs we used to use to build desktop applications, but without the drag-and-drop bit. Rebecca Murphey used a similar pattern in building the Mulberry mobile app framework, which is a perfect use case because Naked Objects is a great way of organizing a composable framework whose implementations will be better served by a different pattern.

Naked Objects模式与MV *有最密切的关系,因此称其为Presentation-Abstraction-Control的变体(相对更远的亲戚)并不是不公平的。 这对于需要包含和呈现自己的数据且视觉表示直接映射到它们包含的数据的大型小部件很有用。 它与我们用来构建桌面应用程序的拖放式IDE相似,但没有拖放位。 丽贝卡·穆菲(Rebecca Murphey)在构建Mulberry移动应用程序框架时使用了类似的模式,这是一个完美的用例,因为Naked Objects是组织可组合框架的好方法,该框架的实现可以通过不同的模式更好地实现。

The third pattern I think deserves more examination is Pipelines. This should be familiar to jQuery developers or anyone who deals with a lot of callbacks. Pipelines chain operations together to affect a shared state, which might be a visual representation or just a set of data (or both!). The interesting thing to me is that we can use this pattern both synchronously and asynchronously, for example applying global functions to initialize, render, and wire-up a page, then use instance-specific functions to wait for user interaction, validate it, attempt to save it, and render again, all the while modifying the state of an abstraction of that page. Anything with a state can have a corresponding state diagram in code, with the ability to modify the path it takes depending on the result of each step.

我认为值得更多研究的第三个模式是管道 。 jQuery开发人员或处理大量回调的任何人都应该熟悉这一点。 管道将操作链接在一起以影响共享状态,共享状态可以是可视化表示,也可以只是一组数据(或两者都有!)。 对我来说有趣的是,我们可以同步和异步使用此模式,例如,应用全局函数来初始化,呈现和连接页面,然后使用特定于实例的函数来等待用户交互,验证并尝试保存并再次渲染,同时修改该页面的抽象状态。 具有状态的任何内容都可以在代码中具有相应的状态图,并且可以根据每个步骤的结果来修改其所采用的路径。

With all of these, as with MVC or any other pattern, you have to consider how and where you want your application tightly or loosely coupled, and whether you need a centralized snapshot of the application, or it's better stored in the components it affects. Things like Naked Objects would be overkill if even your most complex controls are only used once. Things like EDA would be pointless if most of your code is setup and initialization code. And if your site is static, whatever introduces the least framework code while still helping you establish clear conventions would be preferable.

对于所有这些,与MVC或任何其他模式一样,您必须考虑将应用程序紧密或松散耦合的方式和位置,以及是否需要应用程序的集中快照,或者最好将其存储在受影响的组件中。 如果只使用一次您最复杂的控件,则诸如Naked Objects之类的东西就显得过大了。 如果您的大多数代码是设置和初始化代码,则EDA之类的事情将毫无意义。 而且,如果您的站点是静态的,则在引入最少框架代码的同时仍能帮助您建立明确约定的任何方法都是可取的。

At the end of the day, you should still use Backbone rather than not use anything. However, if you find yourself with an application that fits more easily into some other pattern, you shouldn't be afraid to use it. Sadly, for most of these patterns (and the myriad I haven't even mentioned), you're going to have a hard time finding anything as robust and accessible as Backbone. So, more importantly, if you're sitting down to write a new JS application framework, you'd do all of us a service by exploring an alternative to MVC, so picking the right tool for the job won't be a matter of choosing from a selection of nice hammers with different brandnames to tighten screws. Whatever you choose, and whatever the application, though, remember that all implementations decay and it's just as important to leave the opportunity to improve architecture as it is to leave ways to improve the code itself.

最终,您仍然应该使用Backbone,而不要使用任何东西。 但是,如果您发现自己的应用程序更容易适应其他模式,则不要害怕使用它。 可悲的是,对于大多数这些模式(以及我什至没有提到的无数种模式),您将很难找到像Backbone一样健壮且易于访问的任何内容。 因此,更重要的是,如果您坐下来编写一个新的JS应用程序框架,那么我们将通过探索MVC的替代方案为我们所有人提供服务,因此选择适合该工作的工具将不是问题从具有不同品牌的精美锤子中选择,以拧紧螺丝。 但是无论您选择什么,无论使用什么应用程序,都请记住,所有实现都会衰减,并且留下改进架构的机会与留下改进代码本身的方式一样重要。

翻译自: https://davidwalsh.name/beyond-mvc

mvc2 mvc


http://www.taodudu.cc/news/show-4104526.html

相关文章:

  • 应用程序-特定权限设置_在您的应用程序中管理付款:设置网站-代码
  • drupal模块_自动测试Drupal 8模块
  • 为什么您的简历被拒绝-以及如何解决它
  • 从Outlook到python都可以使您的工作减少一半
  • vr手柄设置_最佳无线VR设置,最新和即将推出
  • GloballyDynamic:具有统一客户端API的多平台动态交付
  • word自动更正关闭_如何在OS X中关闭自动更正文本替换
  • Chromium扩展(Extension)的页面(Page)加载过程分析
  • Pizza店(JAVA程序设计)
  • Meatycake,51nod2117,树状数组
  • 全志V3S H.264 对视频进行编码的过程
  • YUV编码为H264 H264封装为MP4
  • 基于Hi3516A的H265 IPC LIVE555 开发
  • ffmpeg入门教程之YUV编码成h264 API详解
  • ffmpeg摄像头采集h264编码RTP发送
  • H.264编码
  • Qt5.12 使用FFmpeg实时解码播放H264/H265摄像头记录(直传数据法)
  • 使用VAE(变分自动编码器),来预测用户流失.
  • Qt基于FFmpeg读取摄像头并进行H264编码
  • H.264/H.265 视频编码解码器单元产品指南
  • C++ 使用Intel Media SDK 实现H.264硬编码
  • 分析FFMPEG中H264编码流程
  • onvif 添加H265开发流程
  • YUV编码为HEVC(H.265)
  • 【FFmpeg】在FFmpeg里添加自研编码器方法
  • FFmpeg —— 13.示例程序(七):视频编码器(YUV编码为H265)
  • 最简单的基于FFmpeg的视频编码器-更新版(YUV编码为HEVC(H.265))
  • obs 推流编码在哪设置_在OBS上进行H265推流
  • 英特尔CAS缓存加速软件优化SSD性能
  • 变分法原理!

mvc2 mvc_MVC之外的世界相关推荐

  1. 为什么数学是理解世界的最佳方式

    来源:遇见数学 在对着乔治梅森大学最近的一届新生致辞时,丽贝卡·戈尔丁(Rebecca Goldin)传递了一个令人沮丧的数据:最近的一项研究显示,36%的大学生在大学四年时间里批判性思维并未显著提高 ...

  2. AGI:走向通用人工智能的【生命学哲学科学】第二篇——思维、生命科学、客观世界

    AGI:走向通用人工智能的[生命学&哲学&科学]第二篇--思维.生命科学.客观世界 导读:关于人类思维的五个层次,博主的评价:这五个层次,有两条主线, 思维需要扩展且没有尽头,逻辑需要 ...

  3. 为什么会有宇宙?宇宙之外会有什么?

    人类是如何起源的?直到今天我们也没有一个准确的答案.更让我们困惑的是我们这个世界这个宇宙,又是如何开始的?是否会终结呢? 宇宙是什么? 在我们课堂知识认知中的宇宙一词,包括了地球在内一切天体的无限空间 ...

  4. “操作系统不以 C 开头和结尾,C 不等于整个世界”

    整理 | 张仕影 出品 | CSDN(ID:CSDNnews) 众所周知,C 是一种被广泛使用的语言,从操作系统内核到加密算法的编写,到处都在使用 C,它在多个领域发挥着重要作用.不久前,国外一位 S ...

  5. 【Visual C++】游戏开发笔记四十七 浅墨DirectX教程十五 翱翔于三维世界 摄像机的实现

    分享一下我老师大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow 本系列文章由zhm ...

  6. HP收购3com给网络世界带来的变化

    HP收购3com给网络世界带来的变化 公元2009年11月12日,互联网上发布了一则消息:HP与3com达成收购协议,3com旗下的唯一的价值资产H3C也随之并入HP网络产品部门.不过从交易的金额来看 ...

  7. 《荒野大镖客》:从西部世界构建到资本社会现象

    "Rockstar为我们展现的不仅仅是西部世界--" 2005年,Rockstar San Diego公布了一段关于"USA.Westland.Cowboy.Gunner ...

  8. 哪所大学教php_世界大学排行榜盘点:THE排名中清华北大雄踞亚洲高校前2!内地大学十强分别是…...

    点击上方蓝字,关注21君~ 走进经济生活里的一切 导读:THE2020年度世界大学排名中,清华大学从去年的第22位下降到今年的第23位,但仍然稳居亚洲高校榜首:北京大学紧随其后,排名上升了七个位次,超 ...

  9. 【Visual C++】游戏开发笔记四十七 浅墨DirectX教程十五 翱翔于三维世界:摄像机的实现...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/zhmxy555/article/details/8657656 作者:毛星云(浅墨) ...

  10. 《平凡的世界》-田晓霞和孙少平 读后感

    <平凡的世界>是很多人高中大学时都看过的书,全书共三部.作者在近十年间广阔背景上,描写了1975到1985年发生在陕北的故事.小说以陕北黄土高原双水村孙.田.金三家的命运为中心,以新的视角 ...

最新文章

  1. 【鸿蒙 HarmonyOS】UI 布局 ( 帧布局 StackLayout )
  2. java blender_[转载]将Blender模型展示于WEB
  3. oracle9i新建数据库的用户有哪些,Oracle 9i数据库的用户创造以及权限分配
  4. 混合云的承诺,收益和产品
  5. js节流函数和js防止重复提交的N种方法
  6. mybatis oracle 大写,解决mybatis用Map返回的字段全变大写的问题
  7. 逆序枚举时常犯的一个错误
  8. 狗不理是怎样混到狗都不理的?
  9. Python动态创建变量的方法
  10. 基于OpenCV实现图像平移
  11. 【转载】SpringMVC访问静态资源
  12. 四、day_03计时、关灯游戏
  13. 大型粒子对撞机已被上面叫停了!何祚庥:希望杨振宁李政道有生之年重归于好...
  14. Java学习实战教程之mysql优化
  15. centos 6.8 请教笔记本上的虚拟机如何配置无线网络 桥接联网
  16. 九爷带你了解 mctop: 监视 Memcache 流量
  17. adb: failed to install xxx Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
  18. Win10系统怎么卸载软件
  19. 网络组建大全(包括企业网、校园网、网吧和基础知识)(转)
  20. git命令上传和下载代码

热门文章

  1. matlab求导函数作图,excel对数据求导作图/如何用excel计算导数
  2. Android中 手机震动功能的实现
  3. 将服务注册到eureka服务端
  4. 初学python爬虫心得(豆瓣电影top250)
  5. CET eve 看星星
  6. 你真的知道如何正确清除 DNS 缓存吗?( 附全平台详细教程 )
  7. 【安全牛】一起来打靶第二周
  8. 正确开启用户实体行为分析(UEBA)番外篇:SIEM与UEBA
  9. dependency
  10. React组件抽象(一): mixin