PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Architecture question - while() loop vs. Application.Run()

Reply

Architecture question - while() loop vs. Application.Run()

 
Thread Tools Rate Thread
Old 30-11-2006, 10:41 AM   #1
Philipp Stader
Guest
 
Posts: n/a
Default Architecture question - while() loop vs. Application.Run()


Hi there,

have been looking into the AdventureWorks Cinema Mobile Client and
adapted the Architecture used there to make use of the Model View
Presenter but don't feel comfortable with it. Especially having to store
results from Views in the Controller to pass them on to the next View
irritates me. After dozens of futile attempts to use a
Application[2].Run based approach that works without a while loop i now
got something working. I just don't know which approach of the two is
the better one. One advantage of the Application.Run approach i saw is
that the application only shows up as one Application in the Running
Programs List where as the while() based solution shows at least two
forms there. This could be a mistake i made though.

I put up a complete working Visual Studio 2005 Solution for download on
http://ph1l.de/netcf/CustomerEditors.zip - CustomerEditor is the while()
approach, CustomerEditor2 is Application.Run. Attachments seem to be not
allowed.

All hints, pointers, opinions appreciated.

Greetings from Switzerland

Phil

Some code inline to follow


The while based approach:


namespace CustomerEditor
{
public enum ControllerState
{
ShowCustomerList,
EditCustomer
}

public class Controller
{
private ControllerState _state = ControllerState.ShowCustomerList;
private bool _doEndProgram = false;
private CustomerModel _customerModel = new CustomerModel();

private Customer _customer;

public Controller()
{
new BackgroundForm().Show();
}

public bool DoEndProgram
{
get { return _doEndProgram; }
set { _doEndProgram = value; }
}

public Customer Customer
{
get { return _customer; }
set { _customer = value; }
}

public CustomerModel CustomerModel
{
get { return _customerModel; }
}

public void setState(ControllerState state)
{
_state = state;
}

public void run()
{
while(!_doEndProgram)
{
switch(_state)
{
case ControllerState.ShowCustomerList:
{
CustomerListPresenter presenter = new
CustomerListPresenter(this);
CustomerListView view = new CustomerListView();
presenter.View = view;
view.ShowDialog();
break;
}
case ControllerState.EditCustomer:
{
EditCustomerPresenter presenter = new
EditCustomerPresenter(this);
EditCustomerView view = new EditCustomerView();
presenter.View = view;
view.ShowDialog();
break;
}
default:
{
break;
}
}
}
}
}
}

Presenters call Close() on their View and set the next State on the
controller. To pass Data between views the Controller has a Customers
property.

The Application.Run() approach:


namespace CustomerEditor2
{
static class Program
{
[MTAThread]
static void Main()
{

BackgroundView view = new BackgroundView();
Controller controller = new Controller(view);
BackgroundPresenter presenter = new
BackgroundPresenter(controller);
presenter.View = view;
Application.Run(view);
}
}
}

The BackgroundPresenter calls controller.showCustomerList()

namespace CustomerEditor2
{
public class Controller
{
private BackgroundView _bg;
private CustomerModel _customerModel = new CustomerModel();

public Controller(BackgroundView bg)
{
_bg = bg;
}

public CustomerModel CustomerModel
{
get { return _customerModel; }
}

public BackgroundView BackgroundForm
{
get { return _bg; }
}

public void showCustomerList()
{
CustomerListPresenter presenter = new
CustomerListPresenter(this);
CustomerListView view = new CustomerListView();
presenter.View = view;
view.Parent = BackgroundForm;
view.Show();
}

public void showEditCustomer(Customer c)
{
EditCustomerPresenter presenter = new
EditCustomerPresenter(this);
EditCustomerView view = new EditCustomerView();
presenter.View = view;
presenter.updateCustomer(c);
view.Parent = BackgroundForm;
view.Show();
}

public void ExitApplication()
{
_bg.Close();
}
}
}

No need to store the Customer in the Controller. The
CustomerListPresenter closes it's view, calls showEditCustomer(Customer)
and passes the selected Customer object.
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off