Eder Andr&#233&#59;s

Hello:

I'm traying the model-view-control to develop clearer applications, but I have many problems. One of these, is a have a control class which will control the logic application, persistence and GUI classes.

My form has a menu and a dark zone, when the user clicks on New Menu, a DataGridView must be shown on the dark zone, but this taks must not done by a form derived class. This task must be done by my own control class, define in other namespace. How can I do it

Do you know about some web link or tutorial to learn the model-view-control using C#



Re: Visual C# IDE Programming in layers

Keith Rome

The key to successful MVC is in successful decoupling of your application layers.

Your Model and View layers should never directly interact - only when asked by the Controller layer. View components are responsible for displaying Models when asked, and for initiating logic (actions) within the Controller layer.

A reasonably good way to do this is to leverage interfaces. Your Model layer should expose a narrow interface that provides the Controller layer with the methods/operations that it needs (usually basic I/O operations). The Model layer should also expose data properties or DVO classes to be used by the View layer when displaying information. The View layer should expose operations and properties that allow manipulation (at a high level!) of the user interface - requesting display of Model data, altering display modes, etc. The Controller layer should primarily expose operations that represent logical system "actions" or "flows".

Simple example: Banking System

  • Model: Data structures for Accounts, Transactions, Users. Interface with Create/Read/Update/Delete operations for those structures.
  • View: Simple interface with operations exposed for DisplayUsersAccounts(), DisplayAccountTransactions(), PromptForPIN(), etc.
  • Controller: Simple class implementing an interface with operations for ChargeAccount(), CreditAccount(), TransferFunds(), Login(), Logout(), SearchForTransactions(), etc.

You could have Model C/R/U/D implementations for various storage engines (SQL, Web Service, XML, etc).

You could have View implementations for various UI platforms (Web, Windows, etc)

Some things to keep in mind:

  • Your View layer should never expose actual Controls - this violates the principle of decoupling.
  • Your View layer should not invoke Model operations directly - the Controller (or some other intermediary) should be doing this.
  • Your Model layer should not care at all about the View layer - the Model should be usable in any environment (web, windows, console, etc).
  • MVC as a pattern is almost never used in isolation without other patterns. Common complementing patterns include: Command, Chain of Responsibility, Facade, Repository, Data Value Object, Plugin, and Provider (lots more, but I see these alongside MVC most often).

HTH






Re: Visual C# IDE Programming in layers

anuraj_p

Hi Keith Rome

I got the idea of sepration of layers, but how can I implement MVC Because if you use a Controller instance in View, the coupling will occur right

Sorry if I am wrong.

Anuraj.P