Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Doesn't this just violate the whole idea of <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow">MVC</a>? Your model is separated from your controller and your view. In this way (the way you propose) you would not be able to replace your model by another implementation, or your controller for that matter.</p> <h3>updated I:</h3> <p>You could of course let your model do the part of the controller as well, but from that moment on you're not talking about the MVC design pattern anymore. For MVC, the model does and should not now about the view. That's the controllers job.</p> <blockquote> <p>The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and viewport to perform actions based on that input.</p> </blockquote> <p>In the MVC pattern, the Model isn't just fixed to your database model, it could be a combination of your database model and a repository pattern as well, where you implement your business logic. </p> <p>The biggest problem I see with your proposal is that it makes code non-reusable. I get a model that is tightly coupled with it's views which I really don't want if I want to reuse the model in whatever way I might want to. </p> <hr> <h3>Update II</h3> <ul> <li><p>I think your are being mislead by the actual word Controller, I had that thought for a while and your latest comment sort of confirms this for me</p> <blockquote> <p>Controllers are some objects, that check correspondence of user input to business-logic.</p> </blockquote> <p>Controllers act upon user input, they might check the user input but their responsibility for checking validity stops there. Business logic goes in the Model (again, the Model as defined by the MVC pattern, not the model as in datamodel). Their main purpose is deciding what View to display. </p></li> <li><p>Also from one of your latest comments: </p> <blockquote> <p>How do you think, if [asp.net mvc] would be developed in my way, would it solve problem of redundant controllers? </p> </blockquote> <p>Asp.Net MVC follows the MVC design pattern. Your proposal does not. It seem more like a ModelControlled View pattern, just to coin a name. Also, there are no redundant controllers, the controllers are no problem, they are an integral part of the solution. </p></li> </ul> <p>And an effort to simplistically clarify what I mean with a code example:</p> <pre><code>namespace DataProject.Model { public class AirportModel { public List&lt;Plane&gt; Planes { get; set; } public List&lt;Pilot&gt; Pilots { get; set; } public List&lt;Passenger&gt; Passengers { get; set; } public List&lt;Flight&gt; Flights { get; set; } } } namespace SomeProject.Repository { public class AirportRepository { private DataProject.Model.AirportModel model; //constructor sets the model somehow public bool AddFlight(Plane plane, List&lt;Passenger&gt; passengers, DateTime time) { //Business logic if (plane.TimeOfDeparture != time) return false; var pilot = (from p in model.Pilots where p.Free &amp;&amp; p.CanAviate(plane.Id) select p).FirstOrDefault(); //More Business logic if (pilot == null) return false; //Add plane, pilot and passenger to database model.Flights.add(new Flight{Pilot = pilot, Plane = plane, Passengers = passengers}); //Even here you could decide to do some error handling, since you could get errors from database restrictions model.Save(); return true; } public List&lt;Planes&gt; GetPlanes(string from, string to) { return (from p in model.Planes where p.CityFrom == from &amp;&amp; p.CityTo == to select p).ToList(); } } } namespace MVCApp.Controllers { public class AirportController { private SomeProject.Repository.AirportRepository repository; [HttpGet] public ViewResult Fly(string from, string to) { var viewModel = repository.GetPlanes(from, to); return View(viewModel); } [HttpPost] public ActionResult Fly(Plane plane, List&lt;Passenger&gt; passengers, DateTime time) { if (!ModelState.IsValid) return View(); if (!repository.AddFlight(plane, pilot, passenger)) return View(); return RedirectToAction("Succeed"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload