AvocadoSoftware.com

Software For Hardcore Developers
Welcome to AvocadoSoftware.com Sign in | Join | Help
in Search

Derick Baileys old blog archives - go to derickbailey.com for new contents

MVP and Semantic Coupling

I was reviewing the design of an MVP setup and the logic that moves between one form and another for the process, today. The basic idea is simple: Presenter calls view.ShowForm, view loads up the new form to work. In the this case, there is an additional requirement of passing various bits of data between the two forms.

As a question on design, I'm looking at the view.ShowForm method implementation, and wondering about the code design used to pass the needed data from the method into the new presenter. The original code looked like this:

//create a new instance of the form
SecondaryForm frm = new SecondaryForm();
SecondaryPresenter presenter = new SecondaryPresenter(frm);

//set the parameters needed for the presenter to process correctly
presenter.AttachParam1AndParam2(myParam, myOtherParam);

//initialize the view
presenter.InitView();

The internals of the AttachParam1AndParam2 just sets a local variable inside of the SecondaryPresenter. Those variables are then used throughout various parts of the presenter. If I were to re-write the code, I would have added the Param1 and Param2 parmaters to the constructor of ReceiptNonRequisitionedPresenter.

//create a new instance of the form
SecondaryForm frm = new SecondaryForm();

//set the receipt process and document in the presenter
SecondaryPresenter presenter = new SecondaryPresenter(frm, myParam, myOtherParam);

//initialize the view
presenter.InitView();

I forwarded this example to my team via an email, asking the question of which way would be considered 'better' and for what reasons. I purposefully left my own opinions on 'why' out of the email, so I could see what my teammates said. One of the team members responded with the same opinions and reasons that I have.

I think parameters to the constructor are “better” because it forces you to give the presenter the references to the ReceiptProcess and Document. What would happen if that presenter was used somewhere else and the programmer forgot/didn’t know to attach? Isn’t this an example of semantic coupling? Semantic coupling is “the most insidious kind of coupling”, according to Code Complete 2 (p102).

I couldn't have said it better.

Published Tuesday, February 27, 2007 11:51 AM by dredge
Filed Under: , , ,
New Comments to this post are disabled

This Blog

Post Calendar

<February 2007>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728123
45678910

Advertisement

News

this is my old blog archives - go to http://derickbailey.com for updates

Syndication

Advertisement

Powered by Community Server, by Telligent Systems