Twisting the Triad – MVC

I have spent a lot of time researching the difference between the MVC and MVP design patterns, as I could not really articulate those differences in a conversation, even though I have used them both in practice. When asking around, I found that a lot of other developers also did not actually know the difference either. So I was in good company.

When you go down this road, you encounter the phrase “Twisting the Triad”. The MVP pattern was arrived at by “Twisting the Triad” (among other things). But the many people who talk about twisting the triad never actually stop to explain what that means exactly. And when I started asking colleagues what is meant by that phrase, I was not surprised to find that no-one (not 1) person could explain what twisting the triad means. Rotating the nodes in the diagram is not quite good enough as an explanation because it has no context. And how far are they rotated? ** Blank looks all round **. Some guys thought it had something to do with the arrows in the diagram. Whilst the difference in the directed arrows between the MVC and MVP diagrams does encompass a huge part of the distinction between the 2 patterns, it does not, in any way, explain what “Twisting the Triad” means.

After much cogitation on the issue, I believed I worked it out one day during my morning shower. But I wanted back-up before I was sure. This theory gave me fresh keywords for Googling and I finally stumbled upon this post by a very well-respected guy in the ASP.NET MVC community. See the last paragraph under the heading The Difference?.

So, without further ado, let me explain what the phrase “Twisting the Triad” means, when used to explain how the MVC pattern evolved into the MVP patten. It is all about which node of the diagram is the first point of contact for the user gesture (or user request). Let me explain with an interactive diagram. The diagram below shows the MVC pattern with the nodes following this colour legend:

  • Red: Model
  • Green: View
  • Yellow: Controller

The arrow represents the user gesture. As you can see, with MVC, the first point of contact for the user gesture is the Controller, which then orchestrates how the application handles that user input.
Now, click the button with the text Twist the Triad!

User Gesture

When you twist the triad by clicking the button, the View now becomes the first point of contact for the user gesture, which is observed by the Presenter i.e. it raises events to the Presenter which then handles those events.

  • Red: Model
  • Green: View
  • Yellow: Presenter

So to recap, this post was about Twisting the Triad. I realise there are other differences between the two patterns. But I’m hoping this post clearly articulates the meaning of “Twisting the Triad”, which so many great developers cannot seem to explain.

2 comments on “Twisting the Triad – MVC”:

  1. i think, it just depends on your team and the tools – then choose the paradigm. i’m pretty sure you can re-build Amazon with both paradigms.
    by the way: which one does e.g. FB use? their just using PHP spaghetti code 🙂

  2. I agree with you. But the post is not so much about a decision as to which pattern to use.
    Its objective is to explain the meaning of Twisting the Triad, which so many developers don’t understand. Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *