`

MVC is dead, it's time to MOVE on.

    博客分类:
  • MOVE
阅读更多

MVC is a phenomenal idea. You have models, which are nice self-contained bits of state, views which are nice self-contained bits of UI, and controllers which are nice self-contained bits of …

What?

I'm certainly not the first person to notice this, but the problem with MVC as given is that you end up stuffing too much code into your controllers, because you don't know where else to put it.

To fix this I've been using a new pattern: MOVEModels, Operations, Views, and Events.

Overview

 

Architecture of a MOVE app

 

I'll define the details in a minute, but this diagram shows the basic structure of a MOVE application.

  • Models encapsulate everything that your application knows.
  • Operations encapsulate everything that your application does.
  • Views mediate between your application and the user.
  • Events are used to join all these components together safely.

In order to avoid spaghetti code, it's also worth noting that there are recommendations for what objects of each type are allowed to do. I've represented these as arrows on the diagram. For example, views are allowed to listen to events emitted by models, and operations are allowed to change models, but models should not refer to either views or operations.

Models

The archetypal model is a "user" object. It has at the very least an email address, and probably also a name and a phone number.

In a MOVE application models only wrap knowledge. That means that, in addition to getters and setters, they might contain functions that let you check "is this the user's password?", but they don't contain functions that let you save them to a database or upload them to an external API. That would be the job of an operation.

Operations

A common operation for applications is logging a user in. It's actually two sub-operations composed together: first get the email address and password from the user, second load the "user" model from the database and check whether the password matches.

Operations are the doers of the MOVE world. They are responsible for making changes to your models, for showing the right views at the right time, and for responding to events triggered by user interactions. In a well factored application, each sub-operation can be run independently of its parent; which is why in the diagram events flow upwards, and changes are pushed downwards.

What's exciting about using operations in this way is that your entire application can itself be treated as an operation that starts when the program boots. It spawns as many sub-operations as it needs, where each concurrently existing sub-operation is run in parallel, and exits the program when they are all complete.

Views

The login screen is a view which is responsible for showing a few text boxes to the user. When the user clicks the "login" button the view will yield a "loginAttempt" event which contains the username and password that the user typed.

Everything the user can see or interact with should be powered by a view. They not only display the state of your application in an understandable way, but also simplify the stream of incoming user interactions into meaningful events. Importantly views don't change models directly, they simply emit events to operations, and wait for changes by listening to events emitted by the models.

Events

The "loginAttempt" event is emitted by the view when the user clicks login. Additionally, when the login operation completes, the "currentUser" model will emit an event to notify your application that it has changed.

Listening on events is what gives MOVE (and MVC) the inversion of control that you need to allow models to update views without the models being directly aware of which views they are updating. This is a powerful abstraction technique, allowing components to be coupled together without interfering with each other.

Why now?

I don't wish to be misunderstood as implying that MVC is bad; it truly has been an incredibly successful way to structure large applications for the last few decades. Since it was invented however, new programming techniques have become popular. Without closures (or anonymous blocks) event binding can be very tedious; and without deferrables (also known as deferreds or promises) the idea of treating individual operations as objects in their own right doesn't make much sense.

To re-iterate: MVC is awesome, but it's designed with decades old technologies. MOVE is just a update to make better use of the new tools we have.

 

P.S. I'm not the only one beginning to think this way either, if you like the idea of MOVE you should check out objectify and interactions which try to add some of the benefits of MOVE to existing MVC applications. Please let me know if you have other links that should be here!

 

 

P.P.S This blog post has been translated into Japanese no fewer than twice: d.hatena.ne.jp andblog.neo.jp. Thanks!
分享到:
评论

相关推荐

    Spring.MVC.Beginner's.Guide.2nd.Edition.2016.7.pdf

    From here, we move on to controllers, views, validations, Spring Tag libraries, and more. Finally, we integrate it all together to develop a web application. You’ll also get to grips with testing ...

    Test-Drive ASP.NET MVC

    This book takes a test-first approach to the main features of ASP.NET MVC. You’ll get hands-on experience building and deploying a time-management web application from start to finish. From building ...

    ASP.NET.Core.1.1.For.Beginners.How.to.Build.a.MVC.Website.2017

    ASP.NET.Core.1.1.For.Beginners.How.to.Build.a.MVC.Website.2017

    精通Spring.MVC

    This book is for Spring or Java EE application developers who want to learn and fully leverage Spring's Web-tier creator and framework, Spring MVC. This book is also for experienced enterprise and ...

    Apress.Pro.ASP.NET.Core.MVC.2.7th.Edition

    Best-selling author Adam Freeman has thoroughly revised this market-leading book and explains how to get the most from ASP.NET Core MVC. He starts with the nuts-and-bolts and shows you everything ...

    Ext.NET.MVC.Pro.2.2.0.MVC.Examples.Explorer.zip

    Ext.NET.MVC.Pro.2.2.0.MVC.Examples.Explorer 包含了所有你需要的控件DEMO。

    Pro ASP.NET MVC 5.mobi

    The ASP.NET MVC 5 Framework is the latest evolution of Microsoft’s ASP.NET web platform. It provides a high-productivity programming model that promotes cleaner code architecture, test-driven ...

    Apress.Pro.ASP.NET.MVC.4.Framework.Jan.2013-Edition 4

    The ASP.NET MVC 4 Framework is the latest evolution of Microsoft’s ASP.NET web platform. It provides a high-productivity programming model that promotes cleaner code architecture, test-driven ...

    Spring.MVC.A.Tutorial.2nd.Edition.1771970316

    This book is for anyone wishing to learn to develop Java-based web applications with Spring MVC. Sample applications come as Spring Tool Suite and Eclipse projects. Table of Contents Introduction ...

    ASP.NET MVC 4 and the Web API: Building a REST Service from Start to Finish

    This one hundred page book focuses exclusively on how you can best use the ASP.NET MVC 4 Framework to build world-class REST services using the Web API. It sets aside much of what the ASP.NET MVC ...

    ASP.NET MVC in Action - Jeffrey Palermo.pdf

    It offers a clearly-written introduction both to the ASP.NET MVC Framework and to the MVC approach. The focus is on creating real, maintainable web applications—so don't expect toy examples and ...

    Microsoft.Web.Mvc.FixedDisplayModes.dll

    Microsoft.Web.Mvc.FixedDisplayModes.dll

    ASP_NET_MVC_4_and_the_Web_API_Jamie_Kurtz.pdf

    ASP.NET MVC has always been a good platform on which to implement REST, but with the advent of the Web API it has now become even better. This book will show you why it's great and how to get the ...

    asp.net mvc

    installing the ASP.NET MVC 2 Release Candidate release on a computer where Visual Studio 2010 Beta 2 is also installed is not supported. Documentation Documentation for ASP.NET MVC 2, which ...

    Bootstrap.for.ASP.NET.MVC.2nd.Edition.17858894

    Grasp the intricacies of Bootstrap and how to use it with ASP.NET MVC Build your own tools and helpers to assist you in creating ASP.NET MVC Bootstrap sites easily and quickly Master the use of ...

    Packt.Hands-On.Spring.Security.5.for.Reactive.Applications

    You will then learn about a variety of authentication mechanisms and how to integrate them easily with the Spring MVC application. You will also understand how to achieve authorization in a Spring ...

    Spring.MVC.Cookbook.1784396419

    You will implement Hypermedia and HATEOAS to guide your customer's stateless conversation with the product and see how a messaging-service based on WebSocket can be configured. Finally you will learn...

    Pro ASP.NET MVC 5.pdf

    The ASP.NET MVC 5 Framework is the latest evolution of Microsoft’s ASP.NET web platform. It provides a high-productivity programming model that promotes cleaner code architecture, test-driven ...

    ASP.NET.MVC2.in.Action

    version of what would later become Microsoft’s ASP MVC framework. What was shown that day would change this developer’s life—and many other developers’ lives—forever. One group of people that was...

    ASP.NET.MVC.5.with.Bootstrap.and.Knockout.js.1491914394

    Bring dynamic server-side web content and responsive web design together to build websites that work and display well on any resolution, desktop or mobile. With this practical book, you’ll learn how ...

Global site tag (gtag.js) - Google Analytics