First let me supply some context by supplying you with the two reads leading to this rant:
Now over to my rant:
So say you are making a passive view with the task of registering a new user. The view might look like this:
public interface IRegisterUserView {
string UserName{get;}
string Password{get;}
event Action OnSubmit;
}
Now the presenter would look something like
public class RegisterUserPresenter
{
private readonly IRegisterUserView _view;
private readonly IUserService _service;
public RegisterUserPresenter(IRegisterUserView view, IUserService service)
{
_view = view;
_service = service;
_view.OnSubmit += submit;
}
void submit()
{
_service.CreateUser(_view.UserName,_view.Password);
}
}
This would be an implementation of the passive view. What if I now, instead of having a two properties UserName and Password in my view, created a whole new object and called it the “Model”
public class Model
{
public string UserName { get; }
public string Password { get; }
}
And then I create a new view that looks like this. To make it even more superviser-controllerish I could remove the event and replace it with a method “Submit”
public interface IRegisterUserView2
{
Model Model { get; }
void Submit();
}
Now the presenter would look something like this:
public class RegisterUserPresenter2
{
private readonly IRegisterUserView2 _view;
private readonly IUserService _service;
public RegisterUserPresenter2(IRegisterUserView2 view, IUserService service)
{
_view = view;
_service = service;
}
public void Submit()
{
_service.CreateUser(_view.Model.UserName, _view.Model.Password);
}
}
The first example is an implementation the “passive view” pattern, and the other is an implementation of the “supervising controller”. The thing separating the two is that in the last example the view works intimately with the model. In the “passive view” example the view knows nothing about the model (which in this example is the IUserService).
But are we really talking about the same model here ? No. We are not. So my claim is that the difference between supervising controller and passive view is minimal. Maybe non existing.
I’m guessing the reason I am having trouble seeing the difference here is due to a lack of understanding of this pattern. I’ll be back with a new post when I finally figure out why the above rant is wrong.