In MVC, why can't a model create a view?

Posted by MUY Belgium on Programmers See other posts from Programmers or by MUY Belgium
Published on 2014-08-21T14:33:25Z Indexed on 2014/08/21 16:27 UTC
Read the original article Hit count: 185

Filed under:
|

I have a web application written in Perl with a controller, some "views" and some "Models". Each "Model" is corresponding to one "View". The controller (one file) creates an Model object corresponding to each view (view is a CGI argument) then retrieve the view from the module it has just created.

Indeed, this should be bad thing but can you argue a bit more about it.

My first idea was that since the object "Model" depends upon the "view", then the "model" is actually a view.

But also the fact that ALL the cgi parameters are passed to the Model causes the "Model" to become not truelly a view but to loose all interest, since it is only related to the current implementation of the web apps. On other words, that the "Model" keep model but loose its "comprehensiveness" ("Model" is not easily understandable).

I'm am quite new in project analysis, so please do not be too harsh. Why is this bad?

I have made a prototype with the main structures I have understood of this web application, made as short as possible.

#Model.pm
package Model;
import {
    # this requires an attribute called "view"
    # and this require an argument which is the cgi params
}
...

#View1.pm
package View1;
...

#Model1.pm
package ModelView1 ;
base Model;
use View1;

sub new {
    my $class = shift;
    my $arg   = shift;
    Model::DoSomething($arg);
    $self->view = new View1($arg);
    ...
}

#controller.cgi
my $model = 0;
...
     $model = new Model1( cgi_param => params() );
     #there is severall models here
...
print $model->get_view()->get_html();

© Programmers or respective owner

Related posts about mvc

Related posts about perl