Is the MVC pattern dead

What is the HMVC pattern?


Reading the Kohana documentation, I found that the main difference in version 3.0 is that it follows the HMVC pattern instead of MVC as it does in version 2.x. The page about it in Kohana's documents and the one on Wikipedia didn't give me a clear idea.

Question: What is the HMVC pattern and how is it different from MVC?



Reply:



I'm in the process of making my own PHP 5.3 HMVC framework called Alloy to develop . Since I am heavily invested and sold in HMVC, I thought I could take a different point of view and maybe a better explanation of why HMVC should be used and the benefits it brings.

The greatest practical benefit of using an HMVC architecture is the "widgetization" of content structures. An example could be comments, ratings, RSS feed ads from Twitter or blogs, or the display of shopping cart contents for an ecommerce website. It is essentially content that needs to be displayed on multiple pages, and possibly even in different places, depending on the context of the main HTTP request.

Traditional MVC frameworks generally do not provide a straightforward answer to this type of content structure. As a result, users generally duplicate and switch layouts, use custom helpers, create their own widget structures or library files, or pull unrelated data from the requested master data controller for push-through to view and partial rendering. Neither of these options is particularly well suited, as the responsibility for rendering a particular piece of content or loading the required data falls into multiple areas and is duplicated in the places used.

HMVC, or specifically the ability to send sub-requests to a controller to meet those responsibilities, is the obvious solution. When you think about what you're doing, it fits the controller structure exactly. You need to load some data on comments and display it in HTML format. So you send a request with some parameters to the comment controller, it interacts with the model, selects a view and the view shows the content. The only difference is that the comments are meant to be displayed inline, below the blog article, which the user is viewing instead of a completely separate full comments page (although with an HMVC approach you can handle both internal and external requests with the same controller and "kill" can kill two birds with one stone "as the saying goes." In that regard, HMVC is actually just a natural by-product of the pursuit of more code modularity, reusability, and better separation of concerns. This is HMVC's selling point.

While Sam de Freyssinet's TechPortal article on scaling with HMVC is interesting, 90% of people who use HMVC frameworks won't get real, practical, everyday benefits from it.







HMVC is closely related to the "component-based" shipping approach. In principle, each controller can act as a dispatcher instead of a single dispatcher who delegates to a controller. This gives you a hierarchy of controllers. The design is more flexible and allows for better encapsulation of code, but at a higher abstraction price. Construct is designed according to this pattern.

See also this answer: / programming / 115629 / simplest-php-routing-framework / 120411 # 120411


At least in Kohana, an HMVC request is an HTTP request that is processed "internally": Instead of being output via the network, it is forwarded, sent and processed by the framework itself. The similarity of the names "HMVC" and "MVC" is confusing in that it suggests an underlying relationship between the terms that does not actually exist: one is not a minor variation or modification of the other, they are entirely different things. (HMVC is also known as Ajax with no client-side HTTP request.) Kohana's emphasis on and support for "HMVC" means that the framework has strong support for an HTTP-based service-oriented architecture.

The advantage of this architecture pattern is that it is trivial for internal and external requests to convert "internal" service requests into "external" requests or vice versa, since the same "calling convention" is used for internal and external requests.

While this is a reasonable architectural pattern, it seems unnecessary to give it a name of its own (Symfony2 describes the same concept of "sub-requirements"), and in fact the name seems to be a misnomer: there is no particular requirement or need that the requirements be a build hierarchy (except for the standard call diagram of every imperative program); For example, the requirements can be slightly recursive.

[ Update April 2011, March 2012: Expanded to reply to reply to comments.]






HMVC is a hierarchical model view controller. In normal MVC, every GUI object has its MVC. However, unlike HMVC, there is no relationship between the parent GUI object and the child GUI object. In HMVC, every GUI object has access to its child objects and every child object can access its parent object.

So in every view there is a superordinate view. This can be used to access the higher-level view. Because in every controller there is a higher-level controller via which the event can be transferred to the higher-level controller (if the event is not in its area of ​​validity).

The new link is this address




We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.