views:

251

answers:

3

There's a lot of confusion over MVC but after flicking through a Head First patterns book (As a side note I hate that brand, though this example was quite good) it claims that MVC or Model View Controller is a hybrid of multiple patterns - mediator, observer etc...

In a recent prototype I did the following, it's C# but should be straightforward.

Person : IPerson {
    public Name { get; set;}
    public Age  { get; set;}
}

IPerson is just an interface defining the above - I've left it out for simplicity.

PersonController : IPersonController {
    public event DetailsUpdated;
    public void SetAge(int age);
    public int GetAge();
    public void SetName(string name);
    public string GetName();
}

I know the above could be properties themselves - but this is just a simple example. The event is fired every time some data changes - e.g. in SetAge/SetName.

interface IView {
    void Initialize();
    void SetAgeClicked(object sender, EventArgs e);
    void SetNameClicked(object sender, EventArgs e);
}

Initialize wires stuff up - e.g. text boxes on the form. SetAge/SetName are the button events - so the form/page etc.. using must have these methods.

Form : IView {

    // IView is implemented.
    // Form is wired up
    // Initialize is set etc...
}

I hear the test of MVC is when you add a new view is it easy to get stuff up and running - well yes it was. However, is this MVC? Is this something else?

Any advice/input would be great. It works - it just want to know why though.

Thanks.

+2  A: 

I'll vote something else.

The reason I say this is there is a ton of debate on what MVC is.

See What's a controller anyway?

Dan Blair
Ok, I'll change it to as a variation or type of MVC.
Finglas
+1  A: 

While that is an implementation of MVC you have there, it isn't using the one Microsoft made and recently released. Overview of it from Scott Gutherie if you want some history. Some may call it MVP where instead of a Controller, that part is called a Presenter that handles business logic and user interaction generally.

JB King
+2  A: 

I would say what you have there is more akin to MVP (Model-View-Presenter) than MVC. There are two main varieties of MVP...Supervising Controller and Passive View. What you have here seems closest to Passive View, which is a pretty classic MVP implementation that people use to improve and abstract WebForms. You can read more about an MVP implementation for WebForms here:

http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx

The same general idea applies to Windows Forms too.

jrista
Ok, I'll look into Passive View. It has cropped up before so I'll check it out.
Finglas