COM Interop and Model-View-Presenter (now Supervising Controller and Passive View)

I had made a couple of comments about implementing the model view presenter at last night’s Edmonton .NET User Group meeting about reasons to use the MVP pattern. I had commented that, at the company I work for, we are using it as a method to decrease the eventual cost of switching from a VB6 font-end WinForms client.
First, it is a rule of COM that types MUST have a default constructor to be implemented through COM. So, it would appear, on first inspection, that that would blow away the dependency injection used in most samples of COM interop. This does not end up to be the case, as I will explain momentarily.
Second, it is also a COM convention to (generally) make a constructor that does not throw exceptions (see response by Harri for a good explanation as to why). 
The general pattern of implementing COM is to instantiate the COM object, then immediately call an Initialize method that can then throw an exception that is more easily handled.
So, this leaves you with an MVP Pattern (Passive Controller) that looks like the following:
public interface IMyView {
    //Methods and Properties implemented by the view



public interface IMyPresenter {
    void Initialize(IMyView view);
    //Other methods implemented by the presenter





public class MyPresenter : IMyPresenter {

    IMyView view;


    // Default Constructor required by COM

    public MyPresenter() { }

    //Overloaded constructor usable in .NET

    public MyPresenter(IMyView view) {


    public void Initialize(IMyView view) {

        if (view == null) throw new ArgumentNullException("view");

        this.view = view;


    //Other methods implemented by the presenter


This truly is the method we are using to decrease the eventual cost of re-implmenting a full .NET solution of our application. So far, it’s working pretty well.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s