mardi 29 août 2017

Is hybridation of design pattern a bad pratice?

My experience and understanding of design patterns comes from working with Laravel, so i'm actually only experienced in MVC design pattern, but I found my self developing a sort of "autocompiling" view for each of the CRUD operations, so for example i usually put some sort of Array in my model to describe how i want the view to be generated for the model itself, and after that i write a general view that read out the model proprieties and based on the array it will generate the fields as required, something like:

class User extends Model{
    public $editFormArray=array(["name","text",20],
                                ["surname","text",30]);
    [...]
}

and the view will have and implementation that loads the model sent to it, and based on the $editFormArray propriety, it will generate itself

Something like:

@foreach($resource->editFormArrayas $currForm)
    @if ($currForm[1]=="text")
        <div class="form-group">
           <div class="col-md-12">
              <input name="" type=""
                     placeholder="" size="">
           </div>
        </div>
    @endif
    [...]
@endforeach

this kind of approach let's me create only 1 view for CRUD operation (and some others view that can't be automatically computed, as per required) and also allows me to change the model form on the fly, adding, removing and editing fields as i see fit on the fly, but also makes my model files be really loaded.

One of my co-worker recently took a course about design patterns and thinks this is bad pratice, saying a normal MVC, with a View manually generated for each single model CRUD operation would be the right way to do it, but i think he is wrong, because the View itself doesn't really compute any real logic (all the logic is actually kept on the controller), it only computes "display logic" as in the logic required to correctly display the UX itself.

Someone could shred some light on the arguments?

Aucun commentaire:

Enregistrer un commentaire