Design patterns Part IV – MVC

The problem:

When your php application became larger, you might find yourself in the situation where you don’t know where to change the design of a certain page, or you might have to change in multiple places to get the same results.
For example, if you want to implement a comments system in your application, you could write a all the code in a single php script, which handles comments listing, adding new comments and all the application logic.

But if the client decide to change the layout of the comments listing, you will see how difficult it is to change all the code that display the comment listing. The same goes if the client decide to change something in the application logic (like storing the data in flat files instead of database tables or adding new fields to the comments).

The solution:

Rather than write the whole application in one script, you should split into three parts:

  • A part to handle the application logic (the model)
  • A part to handle the data displaying (the view)
  • The controller which is the communication interface between model and view

In this way, you can easily change over one part of the application (like changing the html layout), without influence on other components.

Today, many frameworks allows writing code applying the mvc pattern, so you should use this in your advantage.

Related posts:

  1. Design Patterns Part II – Factory
  2. Design patterns Part I – Singleton
  3. Design Pattern Part III – Observer

4 Responses to “Design patterns Part IV – MVC”

  1. Rama says:

    – A part to handle the application logic (the model)
    Typically model represents that Data Model rather than application logic.
    Example: In Java EE world, Session beans handle application logic – session beans are not considered as Model.

  2. Ian says:

    My MVC definition is closer to what Rama suggested. Of course, MVC must be adapted to different code environments (MVC for desktop development is very different than for the web), but I typically suggest the following to those new to MVC:

    Model – Abstracts away your external resources or concepts into a class which acts as an API. Think “model” literally

    View – The template or UI later that users view.

    Controller – This is the glue between the model and view. It makes calls to models, manipulates the responses, and pushes data ready for rendering out to the view.

  3. mario says:

    MVC is an overused phrase. What you’re describing is PMVC or MVP.

  4. cheetty says:

    http://f0i.ru/img2011myfeed/online%20casino/1_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/2_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/3_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/4_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/5_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/6_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/7_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/8_general1.png
    http://f0i.ru/img2011myfeed/online%20casino/9_general1.png

    black black gambling jack jack online yourbestonlinecasino.com
    black casino game jack slot yourbestonlinecasino.com
    accepts card casino credit online
    casino gambling holdem online online poker texas yourbestonlinecasino.com
    online casino online casino sport book
    betting casino gambling internet online result sea
    casino online platinum play
    casino domain online thefreedictionary.com
    betting black game jack poker yourbestonlinecasino.com
    casino gambling lasvegascasinomania.com online online
    casino gambling online review
    gambling gambling online poker yourbestonlinecasino.com
    casino casino online slot slot yourbestonlinecasino.com
    casino casino gambling game las lasvegascasinomania.com online online vegas
    casino game indian online reservation

    7 sultans online casino
    betting casino casino gambling las play vegas yourbestonlinecasino.com
    casino gambling home internet machine slot yourbestonlinecasino.com
    casino casino casino craps las payout play vegas yourbestonlinecasino.com
    casino casino gamerista.com online poker review review usa

    casino fairbiz.biz lotto online uzdrowiciel
    grandonlinecasino.com
    casino online sultan
    casino chicagobestprice.com industry online travel
    16 2006 casino january mt online tb tracked
    new online casino slot
    baccarat casino online recommendation
    online casino mac os x
    your own online casino
    casino online pai gow poker
    best online casino blackjack strategy
    free online video casino game
    casino moneybookers online
    online casino canada
    casino chip online online poker poker poker

Leave a Reply