Saturday, March 5, 2011

MVC vs 3-Tier Pattern

I have had several people ask me what the difference is between MVC (Model View Controller) and Three-Tier architectural patterns. It is my intent to clarify the confusion by comparing the two patterns side-by-side. At least in part, I believe the source of some of the confusion is that they both have three distinct layers or nodes in their respective diagrams.

Three-Tier MVC
If you look carefully at each diagram you'll notice the associations (arrow connectors) between the boxes are set up a little differently.

Three-Tier

A 3-tiered system really is made up of layers (think of cake layers). The UI Layer has access to the Business Logic Layer, and the Business Layer has access to the Data Layer. But the UI Layer cannot directly access the Data Layer. In order for the UI Layer to access data, it must go through the Business Logic Layer via some kind of interface. If it helps, you could think of each layer as one big loosely coupled component with strict design rules of access between layers.

MVC (Model View Controller)

In contrast, the MVC pattern obviously does not keep a layered system. The Contoller accesses the Model (a runtime data repository) and the View. The View then accesses the Model. Exactly how does that work? The Controller ultimately is the logical decision point. What sort of logic? Typically, the Controller will retrieve, build, or modify a Model base on some triggered action. The Controller then decides which View is appropriate via some internal logic. At that point the Controller will push the Model to View.

Note: Because I mostly develop with .NET, Microsoft has adopted the MVC pattern for ASP.NET with their own platform (see http://www.asp.net/mvc). You can certainly use the MVC pattern without Microsoft's platform, but why reinvent the wheel? I have been very happy using it so far.

When Do I Choose Which Pattern?

First of all, these two patterns are definitely not mutually exclusive. In fact in my experience they are quite harmonious. Often I use a multi-tiered architecture, such as a three-tiered architecture, for the overall architectural structure. Then, within the UI Layer, I use MVC. Something like the diagram below.

22 comments:

  1. Hi Suma,

    I'm not sure if there is a good code example that will clearly show this. Your MVC project is your UI layer. Your business logic or mid-tier layer technically could be in your MVC project, but I prefer to have any other combination of linked projects or services externally or in your solution. This keeps some defined boundary (though not perfect) for other developers to have the UI and mid-tier layer separated. Your data layer is typically something like a database or file system. You keep your three-tier system in line by never allowing your UI and data layers to communicate directly with each other. The UI layer must make calls to the business logic layer to get data from the data layer.

    I hope that helps. Let me know if you need any further clarification.

    ReplyDelete
  2. Hi BRYAN recently i attended one interview in that they asked me what is MVC architecture and give one example to illustrate.I just explained what is MVC. but i cant able to explain the example.Can u pls put ur effort to give simple example based on MVC architecture.Thanks in advance BRYAN.

    ReplyDelete
  3. Hii This is sandeep Rath(software developer in mvc) any body wants asp.net mvc realtime projects then mail me.my mailid is sr034937@gmail.com

    ReplyDelete
  4. Hi,
    What's difference between DAL, Model and BLL in your example?

    ReplyDelete
  5. Programming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. Beginners Heap also provides latest tutorials of Programming from beginning to advance level.
    Be with us to learn programming in new and creative way.

    ReplyDelete
  6. Great work to sharing this. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand advaced concepts. As a beginner in Dot Net your post help me a lot.Thanks for your informative article.
    dot net training in velachery | dot net training in chennai

    ReplyDelete
  7. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Digital Marketing online training

    full stack developer training in pune

    full stack developer training in annanagar

    ReplyDelete
  8. I am really happy with your blog because your article is very unique and powerful for new reader.
    Click here:
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune

    ReplyDelete
  9. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    python training in OMR
    python training in Bangalore
    python training in rajajinagar
    Python training in btm
    Python training in usa

    ReplyDelete
  10. Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read  about their market situation nowadays.
    Blueprism training in Pune

    Blueprism online training

    Blue Prism Training in Pune

    ReplyDelete
  11. Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate
    Data Science training in kalyan nagar | Data Science training in OMR
    selenium training in chennai | Data Science training in chennai
    Data science training in velachery | Data science online training

    ReplyDelete
  12. This is beyond doubt a blog significant to follow. You’ve dig up a great deal to say about this topic, and so much awareness. I believe that you recognize how to construct people pay attention to what you have to pronounce, particularly with a concern that’s so vital. I am pleased to suggest this blog.

    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  13. Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  14. myTectra a global learning solutions company helps transform people and organization to gain real, lasting benefits.Join Today.Ready to Unlock your Learning Potential !Read More...

    ReplyDelete
  15. Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.


    AWS Tutorial |Learn Amazon Web Services Tutorials |AWS Tutorial For Beginners

    AWS Training in Chennai |Best Amazon Web Services Training in Chennai


    Amazon Web Services Training in Pune | Best AWS Training in Pune

    ReplyDelete
  16. Selenium is one of the most popular automated testing tool used to automate various types of applications. Selenium is a package of several testing tools designed in a way for to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms and for the same reason, it is referred to as a Suite.

    Selenium Interview Questions and Answers
    Javascript Interview Questions
    Human Resource (HR) Interview Questions

    ReplyDelete
  17. Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays. Well written article.Thank You for Sharing with Us angular 7 training in velachery

    ReplyDelete