Why is MVC design template widely used for website development?

I am developing my knowledge of OOP design patterns, and since the main focus is website development and web application development, I tried to find examples of design patterns in these areas, but it seems to mainly use web frameworks (any other examples should be appreciated ) It seems to me that most (all?) PHP-based frameworks seem to use the MVC design pattern. Since this is most widely used, would it be correct to assume that this is the best design pattern for this type of development or is it a reflection of a lower learning curve than other design patterns?

I also noticed that the codeigniter structure uses both a singleton pattern and an MVC pattern. Is this hybrid design model common and effective, or was it used in codec for some reason?

+6
oop php design-patterns frameworks codeigniter
source share
5 answers

They use the MVC pattern by name. This buzzword was chosen because it is widely known. The way the concept is used for web applications has a mediocre resemblance to the original template.

This is useful for the general nomenclature and because people have a vague understanding of what it should do. However, there are more efficient templates, and, for example, Model-View-Presenter better describes what is done in practice (the term is simply not used, because it is unknown). And there are other options that have technically replaced MVC.

Singletones are another idea for structuring code. This is not related to the way you develop the overall application flow. This is one of several descriptive terms intended to identify idioms of the general structure of objects. The term is overused due to the expansion of its fame. In practice, this is neither important nor important for a good application design.

Here is a brief overview of the template names for common object API templates:
http://www.fluffycat.com/PHP-Design-Patterns/

Some discussions of the basic concepts of MVC here (may not be relevant, but very interesting):
http://c2.com/cgi/wiki?MvcIsNotImplementable
http://c2.com/cgi/wiki?MvcIsNotObjectOriented

+3
source share

I think you confuse some concepts here. First of all, MVC is not quite a design template, but a more general concept of organizing an application. B / c there is no one, no better implementation for MVC. MVC is what your common sense tells you about structuring data processing. Separate what you see from what is going on inside and what information is processed at all.

Singletones are commonly used b / c in MVC, you have many different objects using the same resources. To organize the fact that you can use a registry implemented as singelton to access a database, for example.

Best wishes

Raffael

EDIT:

in fact, there are many different ideas about what a useful implementation of an MVC structure should look like.

For example, in books you usually see three windows, the Labeles model ',' view 'and' controller '. And they are all connected by arrows. IMO, the relationship between the "view" and the "model" should be ignored because the model must be handled by the controller that communicates with the view.

I also think that it is very important to distinguish between business logic and the controller. Mix lightly. But BL belongs to the model level. In this sense, I do not think of MVC as something like a triangle, but a three-element system V / C / M.

+1
source share

With the development of the website, basically two processes take place. You have a server side where data is collected and / or processed. Then there is the client side where something needs to be presented. (Some data is passed to Views at this point)

As you know from OOP, it is good practice to add structure to the data being processed. That's where the models come in. Finally, you have controllers that process the models and then pass the data to the views.

We can say that MVC is the offspring of two principles: separation on the server / client side and OOP.

Regarding singleton classes: they are really used for sharing resources such as a database.

+1
source share

Because it makes sense! :)

All this concerns the separation of the various parts of your application into specific layers. Each layer should do only what is associated with a particular problem. In MVC, these problems are Model, View, and Controller. When your application is divided into layers that work independently of each other, you have a so-called untied application. This is good because it allows you to test each layer without involving other layers. Theoretically, you can also completely replace one layer with a new implementation without changing the other layers.

  • Model - responsible for business logic and perseverance

  • Controller - transfers the application and acts as a bridge between the model and the view

  • View - represents the model to the user

+1
source share

Generally:

  • MVC (Model-View-Controller) is a software architecture.
    Important: there is no MVC design pattern;)
  • A design pattern is a common reusable solution to a common problem in software development. In other words: this is like best practice for a common problem.
    • Examples: Singleton, Factory Method, Adapter, Decorator, etc.

So why is MVC often used?
The reason is quite simple: if all project developers are familiar with MVC (or another architecture), they have a general idea of ​​where to place the code or where to look for the code. It's about being efficient and writing good code. Therefore, in the end we are talking about a common understanding.

+1
source share

All Articles