The rule of separation - do not try to abuse!

    The commentary on the article on the “rules of separation” turned into a small separate article, which again proves that the development of any application is more complicated than Hello World requires informed decisions and a creative approach, sometimes refuting these same decisions.

    In his article , Rauf cites MVC as a very correct design pattern using responsibility sharing. I would not agree with this, and the first good template separation that comes to my mind is Observer.

    In my opinion, MVC, like MVP (Model View Presenter) templates are powerful, but quite blurry. This means that you can never draw a clear line between M, V and C / P - i.e. without reference to a specific project, you can never say where the controller ends and the presentation begins, or what code we will write in the model, and which in the controller.

    As for the web / client-server / server-side + JS + AJAX, I would also not very agree with the fact that we need to very strictly divide the logic and presentation.

    Here's the thing:

    1. Again, the edges are blurred - the simplest example is the same project selling kiosk computers in Svyaznoy. Here, of course, the specifics of the application play a role (and I lead to that)! Have you ever seen that the basket is stored and processed on the client side (in the browser), and stored on the server side, only at the end of the path - after clicking the "Order" button? This is exactly the case with us.

    2. Again about blurry faces and the same offline web application (yes yes, I did NOT seal it). The application has a lot of client-side code, and JavaScript is a specific language (callbacks, closures, runtime extensions). In some places, you have to use mega-hacks, which I personally don’t seem to be able to put in order. How would you, for example, deal with Deferred Rendering in Chrome / Chromium ??? About when and how Chromium renders lazily / deferredly planning a separate article.

    So - the data is pulled using AJAX from the server - it would be received in JSON, and rendered already on the client ... There it was - the specifics of the application dictate not sending JSON, but HTML - otherwise the brakes and again rest on deferred rendering.

    3. The DOM-Model, CSS, and JavaScript are fairly closely related. I would like to do some things with clean markup, for example, dice with rounded frames and shadows - a picture, but it turns out when there are a lot of them - the brakes start and you have to use CSS3 (we’re easier - we only have Chromium). For animation, I would like to use CSS3-Animation, kindly provided by the WebKit engine, but practice shows that it slows down resource-demanding.

    Summary of DOM + CSS + JavaScript + AJAX:

    The implementation is strongly influenced by technology and channel width. As a result, you often have to do not how beautiful it is, but how it will work well. Well, it turns out that govnokod and crutches rule, no matter how much it surprised me myself ...

    But let's get back to MVC ... I would like to say that it’s not worth it to abuse. Take for example the simplest govnosayt business card, which I at one time produced a dozen or two.

    As usual on each page we have a sidebar with news. This is where the dilemma arises and the edge between the Controller and View becomes soft ...

    Go to business! It would be nice to make a selection of the collection of the last five news in the controller, but I personally do not like it for one simple reason - it will have to be done in each (almost) controller.

    An experienced OOP specialist :) will say that you need to select the parent class CommonController with the fetchLastNews method, which will be launched every time immediately before the main * Action is executed. There it was !!! Imagine that this is not just the five latest news, but some rather heavy selection (and caching doesn’t work for us), and only 65% ​​of the pages are used for this news. Inherit controllers from different base classes ??? MESS!!! (IMHO)

    But a graceful crutchThere is a way out if you have a template engine with simple execution of PHP code (how things are in other languages, I still have little idea) - I usually use Macro from or native-php (Smarty, although it works, but the code execution in I don’t like it {PHP} TIN {/ PHP}) ... So, if you have a good PULL template engine, it’s better to break the V | C line in this place and make a news sample in the subpattern, which can be pulled up at any time template / Layout with the Include statement.

    I already foresee the tomatoes flying into me from MVC adherents (and I love him too), but the article is not intended to refute its power, but only to emphasize the blurriness of components, in order to warn developers who see a silver bullet in MVC.

    There is no silver bullet - there is a golden mean, but you (and me) have yet to find it.

    Also popular now: