473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Model-View-Controller implementation question in .NET

Two questions really, the first one "conceptual" and the other more involved
with design:

1 - There are two schools of thought where I work on the role of the
"controller" task.

The first is that the business object will provide the business rules and
that the controller will implement the rules and then pass the result set to
the view (i.e. do most of the grunt work).

So for example, the business object may have two methods. The first one
provides a list of menu items and the second provides a list of who can see
what. The controller then prunes the list of menu items down to those that
can be accessed by the particular user and passes the result to the view.

The second is that the business object has one method that gives the menu
items that the end user can see and the controller simply passes this to the
view. (i.e. the BO does most of the grunt work and the controller just has
the logic of knowing where to get this data and where to send it - i.e.,to
the view).

Personally, I subscribe to the second one. The reason is that if I have one
BO that happens to be consumed by n controllers, then I don't want to
replicate the implementation of the business rules n times, just the once.

However, what is the general consensus of opinion?

2 - I've just read in an article "MVC infrastructure that doesn't harm
ASP.NET mechanism" that implementing the MVC pattern isn't truly compatible
with the ASP.NET 2.0 framework: http://www.codeproject.com/aspnet/NWAF.asp

Do people concur with this?

If so, what advice can people give me? I've got to re-write a CLASSIC ASP
eCommerce application that is not that complicated a site in terms of the
number of pages etc, but it does have a heavy load (it's a B2B system with ~
3/4 million users)

Thanks in advance

Griff
Jan 26 '06 #1
4 914
The idea behind MVC is that the Data (Model) is hidden from the outside
world. That way if it changes, or how you implement it changes, the outside
world does not care/know. The Controller (API) is what the outside world
uses to gain access to the data but in a non-data-implementation-specific
format (ie. you dont want to return a Collection because later on you may
change to use a fixed array of objects instead.)

Example:
A class that keeps track of people. The person calling the controller has no
idea that the Model uses collections to keep track of data, or that there
are 2 different collections in use (one for age and one for name). If I
decide to change how I store the data later on (maybe I will store the data
in a database instead of in memory) the outside world would not have to
change how they access the Controller because the API they are using does
not change.

public class Controller
{
private Model m_model;

public int Count
{
{ get m_model.m_names.Count; }
}

public string GetName(int index)
{
return (string)m_model.m_names[index];
}

public int GetAge(int index)
{
return (int)m_model.m_ages[index];
}

public itn AddPerson(string name, int age)
{
m_model.m_names.Add(name);
m_model.m_names.Add(age);
}
}

public class Model
{
public ArrayList m_names;
public ArrayList m_ages;
}

Hope this helps!

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Griff" <Ho*****@The.Moon> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Two questions really, the first one "conceptual" and the other more
involved with design:

1 - There are two schools of thought where I work on the role of the
"controller" task.

The first is that the business object will provide the business rules and
that the controller will implement the rules and then pass the result set
to the view (i.e. do most of the grunt work).

So for example, the business object may have two methods. The first one
provides a list of menu items and the second provides a list of who can
see what. The controller then prunes the list of menu items down to those
that can be accessed by the particular user and passes the result to the
view.

The second is that the business object has one method that gives the menu
items that the end user can see and the controller simply passes this to
the view. (i.e. the BO does most of the grunt work and the controller
just has the logic of knowing where to get this data and where to send
it - i.e.,to the view).

Personally, I subscribe to the second one. The reason is that if I have
one BO that happens to be consumed by n controllers, then I don't want to
replicate the implementation of the business rules n times, just the once.

However, what is the general consensus of opinion?

2 - I've just read in an article "MVC infrastructure that doesn't harm
ASP.NET mechanism" that implementing the MVC pattern isn't truly
compatible with the ASP.NET 2.0 framework:
http://www.codeproject.com/aspnet/NWAF.asp

Do people concur with this?

If so, what advice can people give me? I've got to re-write a CLASSIC ASP
eCommerce application that is not that complicated a site in terms of the
number of pages etc, but it does have a heavy load (it's a B2B system with
~ 3/4 million users)

Thanks in advance

Griff

Jan 26 '06 #2
Hi Charles

Great simple example - thanks.

Just extending it a little....if you wanted to add a business rule to say
that a particular end user can NOT add users, then should you add this
business logic to the controller or should you incorporate it in the model
class?

I'm guessing that the Model is not just data but business rules too? Am I
wrong?

If I'm right then you'd have to call a method on the model class that adds
the new user to a PRIVATE array and this method has an additional argument
to say who is trying to add the new user and use a business rule to decide
whether or not the new user should be added.

Thanks

Griff
Jan 26 '06 #3
I guess it depends on the situation and implementation of the particular
system. Take the following scenario as an example of what I mean.

You have a backend system (database) that has 2 different front ends (web
and desktop application). Now, the Web side you only want to allow Queries
to be done but the desktop app. can add/delete/etc. Both of the front ends
could use the same Model but use different Controllers to access it. The
business logic in this setup would probably be in the Controller since it
would be different between the two front ends. You would use two different
controllers as a security measure so that no matter what the Web front end
does not even have the "code" (Controller) to perform add/delete/etc.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Griff" <Ho*****@The.Moon> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Hi Charles

Great simple example - thanks.

Just extending it a little....if you wanted to add a business rule to say
that a particular end user can NOT add users, then should you add this
business logic to the controller or should you incorporate it in the model
class?

I'm guessing that the Model is not just data but business rules too? Am I
wrong?

If I'm right then you'd have to call a method on the model class that adds
the new user to a PRIVATE array and this method has an additional argument
to say who is trying to add the new user and use a business rule to decide
whether or not the new user should be added.

Thanks

Griff

Jan 26 '06 #4
CC - thanks!

Griff
Jan 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Flare | last post by:
Hi I tring to implement a model 2 architecture in a new test JSP site for my own training. I read this article...
1
by: Abhijit | last post by:
I am working in a data warehousing environment which gets sourced from Oracle ERP (AR/GL/AP). The dimensional entities associated with incoming data are GL Code (e.g. 110), Department (e.g. 1050),...
10
by: Michael Strorm | last post by:
Hi! I've been having problems with a DTD. Having had the Sun XML validator reject a document, I put it through 'xmllint' for more information. 'Xmllint' noted a problem with the DTD itself;...
4
by: Davíð Þórisson | last post by:
Hi, when I was programmin ASP/JScript I had a very nice utilitiy which I got from MSDN (Script56.CHM). It's simply a help file but containing object orientiated documentation of all scripting...
5
by: clintonG | last post by:
I'm looking for documentation and would not turn my nose up to any code from anybody who thinks they are good at the design of an algorythm that can be used to generated a hierarchical relational...
5
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
1
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
3
by: Andy B | last post by:
I have about 12 services that will be used on the website I am working on. A few of them are News, Events, Venues (that work directly with Events), Mailing lists and some others. Each one of these...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.