MVC question
-
Hi, im implementing a simple MVC pattern in my C# application. Ive never used this technique before so I figure things out as I go, looking at code reading articles etc. A thought has come up though.. As I understand it u usually have one controller for each set of related functionality. In that case I will need to instansiate the same controller from different winforms passing along a reference of the view. Im not such an experienced programmer but I can see some problems with this approach. Any suggestions/thoughts how to handle this? /thanks
-
Hi, im implementing a simple MVC pattern in my C# application. Ive never used this technique before so I figure things out as I go, looking at code reading articles etc. A thought has come up though.. As I understand it u usually have one controller for each set of related functionality. In that case I will need to instansiate the same controller from different winforms passing along a reference of the view. Im not such an experienced programmer but I can see some problems with this approach. Any suggestions/thoughts how to handle this? /thanks
Perhaps I'm missing something in your question, but why would you want to instantiate the controller from different forms? This negates the usefullness of the MVC pattern. What you really want to do is instantiate your controller in one place and then *pass* that around as you need it. I usually use a Mediator class to handle this. The Mediator is responsible for instantiating the controller, and contains the reference to it. The controller is made available as a property from the Mediator.
Deja View - the feeling that you've seen this post before.
-
Hi, im implementing a simple MVC pattern in my C# application. Ive never used this technique before so I figure things out as I go, looking at code reading articles etc. A thought has come up though.. As I understand it u usually have one controller for each set of related functionality. In that case I will need to instansiate the same controller from different winforms passing along a reference of the view. Im not such an experienced programmer but I can see some problems with this approach. Any suggestions/thoughts how to handle this? /thanks
Model View controller is a set of patterns, and has been implemented in many ways. The main idea behind a MVC is you seperate your view (Screens) from the model (Business Objects) through a center controller. Other patterns can be used here to further abstract the connections, but to keep things simple a good way to accomplish this is to first understand that your screens should know nothing of the business objects. A central controller class is usually constructed to support the "awareness" of the eventing on the view (screens). The controller then wires up to the business objects to do the work. Eventing, Interfaces and sometimes other design patterns are used for this "wiring" of abstraction between the view of the model. For instance, I've just completed a project in which that I implemented a MVC. I added an additional layer of abstraction using a Command pattern. This pattern, when implemented on the Controller and the View, gives a very abstract way of defining actions. Within the view, I constructed CommandAdapters that adapted each of my commands to the controller. The controller also used the commands for communication back to the view. There is alot of debate in the industry on the best ways to create n-tier applications. I've learned that if an application is going through alot of changes, and new enhancements are readily being introduced. Then it is worth the extra time architecting a sound MVC approach. However, if the project is simple, doesn't change much, or there isn't enough funding available. Then using agile development techniques is the better bet. Hope this helps! ~ CodeDoctor ~