Why is MVC design pattern used extensively for website development? Why is MVC design pattern used extensively for website development? codeigniter codeigniter

Why is MVC design pattern used extensively for website development?


They use the MVC pattern by name. It's a buzzword picked because it's widely known. The way the concept is used for web applicatons has mediocre resemblence to the original pattern.

It's useful for a common nomenclature and because people have a vague understanding of what it is supposed to do. There are better patterns however, and for example Model-View-Presenter describes better what's done in practice (the term is just not used, because it's unknown). And there are other variations which have technically superseded MVC.

Singletons are another code structuring idea. It is unrelated to how you design the general application flow. It's one of a few descriptive terms intended for identifying common object structure idioms. The term is likelwise overused because of the extend of its fame. In practice it's neither important nor significant for good application design.

Here's a short overview for the design pattern names of common object APIs:
http://www.fluffycat.com/PHP-Design-Patterns/

Some discussions on the core concepts of MVC are here (maybe not relevant but highly interesting):
http://c2.com/cgi/wiki?MvcIsNotImplementable
http://c2.com/cgi/wiki?MvcIsNotObjectOriented


With website development, there are basically two processes going on. You have the server side, where data is gathered and/or manipulated. Then there is the client side where something needs to be presented. (Some data is passed to Views in this step)

As you know from OOP, it is good practise to add structure to the data you are processing. This is where models come in. Finally, you have controllers who do processing on the models, and then pass data to the views.

You might say that MVC is the offspring of two principles: server/client side separation and OOP.

As for the singleton classes: these are indeed used for sharing resources like the database.


Because it makes sense! :)

It's all about separating different parts of your application into specific layers. Each layer should only do things related to a specific concern. In MVC those concerns are Model, View and Controller. When you have your application divided into layers that work independently from each other you have what is called a decoupled application. This is good as it lets you test each layer without involving the other layers. In theory you can also completely replace one layer with a new implementation without changing the other layers.

  • Model - Responsible for the business logic and persistence

  • Controller - Drives the application and works as a bridge between the model and the view

  • View - Presents the model to the user