We frequently keep running into the same set of inconsistent practices
around models and views and would like some other opinions.
1) There is no such thing as a "Controller " in C#. Developers keep
creating them, but in the purist sense they can't exist in C#. The View
and Controller are always one.
2) Exposing the internal structure of the Model to pass its contents to
something else (often another model) is bad. Let's say the model's
internal data structure is an ArrayList (for now). Developers often
will add a property to get this array list out. I argue that you should
add an interface to the Model to get the "Elements" of that ArrayList.
This way if you extend the model you just extend that interface and you
maintain appropriate access to the model rather than some
representation of its internals. It also avoids the whole issue of
returning a reference to the internal versus copying it. Passing a
reference to the ArrayList doesn't scale well as the model develops.
3) Who owns the model? Does the View Own the Model? If so when the View
is destroyed and something wants access to the data in the Model it's
kinda gone. If the Object that created the View is also responsible for
creating the Model this seems to break the encapsulation.
4) Can the Model ever directly reference a View? This gets messy. If we
create a Dialog (that we decide is simple enough that requires no
model) is it legitimate for the Model to call the Dialog. But then we
run into window ownership issues, since the model has no "Window"
and the Dialog wants a parent window. I think it's pretty clear that
the model should not directly reference any of it's "own" views
and only do that through subscribed events.
5) The Busy loop. This is how it usually goes. We add an update event
and any time the model changes we fire it. Then things start to get
complicated and we introduce a BegingUpdate/EndUpdate set of methods
(these control if update events should be fired or not). Then a bunch
of code evolves some using BeginUpdate/EndUpdate and some not. An valid
argument one developer keeps saying is, don't have the UpdateEvent
and then we don't need te BeginUpdate/EndUpdate and the let users of
the model explicitly call FireEvents().
6) Visual Studio Dialog Designer. This thing just seems to get in the
way. It discourages Model/View design and you have to go very out of
your way (and it's way) to have a Model/View based window. There are
many threads that discuss the issue is also the .Net WinForm library is
just poor plain poorly designed. 2 1164
Right...because as we all know, the ONLY way to design a UI is with the MVC.
Thats why FMC was such a raving hit!!!
whats your point?
"mswlogo" wrote: We frequently keep running into the same set of inconsistent practices around models and views and would like some other opinions.
1) There is no such thing as a "Controller " in C#. Developers keep creating them, but in the purist sense they can't exist in C#. The View and Controller are always one.
2) Exposing the internal structure of the Model to pass its contents to something else (often another model) is bad. Let's say the model's internal data structure is an ArrayList (for now). Developers often will add a property to get this array list out. I argue that you should add an interface to the Model to get the "Elements" of that ArrayList. This way if you extend the model you just extend that interface and you maintain appropriate access to the model rather than some representation of its internals. It also avoids the whole issue of returning a reference to the internal versus copying it. Passing a reference to the ArrayList doesn't scale well as the model develops.
3) Who owns the model? Does the View Own the Model? If so when the View is destroyed and something wants access to the data in the Model it's kinda gone. If the Object that created the View is also responsible for creating the Model this seems to break the encapsulation.
4) Can the Model ever directly reference a View? This gets messy. If we create a Dialog (that we decide is simple enough that requires no model) is it legitimate for the Model to call the Dialog. But then we run into window ownership issues, since the model has no "Window" and the Dialog wants a parent window. I think it's pretty clear that the model should not directly reference any of it's "own" views and only do that through subscribed events.
5) The Busy loop. This is how it usually goes. We add an update event and any time the model changes we fire it. Then things start to get complicated and we introduce a BegingUpdate/EndUpdate set of methods (these control if update events should be fired or not). Then a bunch of code evolves some using BeginUpdate/EndUpdate and some not. An valid argument one developer keeps saying is, don't have the UpdateEvent and then we don't need te BeginUpdate/EndUpdate and the let users of the model explicitly call FireEvents().
6) Visual Studio Dialog Designer. This thing just seems to get in the way. It discourages Model/View design and you have to go very out of your way (and it's way) to have a Model/View based window. There are many threads that discuss the issue is also the .Net WinForm library is just poor plain poorly designed.
"mswlogo" <ms*****@hotmai l.com> a écrit dans le message de news: 11************* *********@g43g2 00...legr oups.com... 1) There is no such thing as a "Controller " in C#. Developers keep creating them, but in the purist sense they can't exist in C#. The View and Controller are always one.
We have designed our own MVP (Model View Presenter) framework in Delphi and
are porting it to C# with no problems at all.
The Presenter (Controller) is definitely a viable separate entity and we are
even thinking of making it a RAD component.
2) Exposing the internal structure of the Model to pass its contents to something else (often another model) is bad. Let's say the model's internal data structure is an ArrayList (for now). Developers often will add a property to get this array list out. I argue that you should add an interface to the Model to get the "Elements" of that ArrayList. This way if you extend the model you just extend that interface and you maintain appropriate access to the model rather than some representation of its internals. It also avoids the whole issue of returning a reference to the internal versus copying it. Passing a reference to the ArrayList doesn't scale well as the model develops.
IMO the Model should contain a "Value" which is the real business object.
The Value contains any properties and methods that pertain purely to
behaviour the business object alone. But if there is behaviour that affects
objects related to the Value type, then that behaviour should be a part of
the Model class.
3) Who owns the model? Does the View Own the Model? If so when the View is destroyed and something wants access to the data in the Model it's kinda gone. If the Object that created the View is also responsible for creating the Model this seems to break the encapsulation.
The Presenter (Controller) can own the Model but it is not necessary that
any one class does so. It is the job of the Presenter to either create or
link to a View.
Your application code will usually create an instance of a business class
and then pass that to the constructor of the Presenter; in essence this can
be said to be "presenting the business object".
The Presenter then creates an appropriate Model and passes the BO to its
constructor so that it then becomes the Value of the Model. Nothing takes
ownership of the BO, it is "owned" by the app code that created the
Presenter.
The Presenter also is responsible for creating a View if a whole object is
being edited and a form is required; but it only links the View to the
Value/Model in the case of an edit displaying a property of of an object.
4) Can the Model ever directly reference a View? This gets messy. If we create a Dialog (that we decide is simple enough that requires no model) is it legitimate for the Model to call the Dialog. But then we run into window ownership issues, since the model has no "Window" and the Dialog wants a parent window. I think it's pretty clear that the model should not directly reference any of it's "own" views and only do that through subscribed events.
The Model/Value should never know anything about the UI that is used to
display/interact with it. As I have said the Presenter is the class that
owns both the Model and the View in the case of a form, but only the Model
in the case of an edit control.
You should be using the Observer pattern to link the View to the Model. I
use Interactors to react to the events of the View and translate those
"gestures" into Commands on the Model.
5) The Busy loop. This is how it usually goes. We add an update event and any time the model changes we fire it. Then things start to get complicated and we introduce a BegingUpdate/EndUpdate set of methods (these control if update events should be fired or not). Then a bunch of code evolves some using BeginUpdate/EndUpdate and some not. An valid argument one developer keeps saying is, don't have the UpdateEvent and then we don't need te BeginUpdate/EndUpdate and the let users of the model explicitly call FireEvents().
The Model and/or the Value should be the Subject in the Observer pattern and
the View should be attached to this Subject. In MVP, the Interactors that
respond to events from the View can be enabled or disabled to avoid any
circular reactions to updates from the Model triggering further reactions in
the Model.
Begin/EndUpdate are useful if several changes in data should be reflected in
the UI to avoid flickering.
6) Visual Studio Dialog Designer. This thing just seems to get in the way. It discourages Model/View design and you have to go very out of your way (and it's way) to have a Model/View based window. There are many threads that discuss the issue is also the .Net WinForm library is just poor plain poorly designed.
We use the form/dialog designers in Delphi and C# to layout forms and set
the names of controls to equate to the names of the properties that they are
to display. The Presenter links up the edits to the properties when it
creates one sub-presenter for each property.
We have not created a designer for use in the IDE but it is something in the
pipeline and looks to fairly easy to implement. AFAICS, the designer should
represent/edit the Presenter and should take the form of a design surface
that creates non-visual classes.
There are some articles about MVP using Delphi on my website : www.carterconsulting.org.uk
Joanna
--
Joanna Carter
Consultant Software Engineer This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fardude |
last post by:
I developed a search stored proc that searches all or
some of Procs, Views, Triggers and functions. Would anyone be interested
to see it posted here?
Do you have any suggestions about other places, websites forums ...., to
share something I have developed?
Thanks you for your response in advance
PLease send me email
|
by: todd |
last post by:
here is a search tool SP I wrote.
How many times have you wanted to search all your Stored procs or views (in
a
database) for a keyword but couldn't!?
Well now you can! THis can makes life a lot easier for developers.
Would you email me and let me know which part of the world my code is
running in?
|
by: Saradhi |
last post by:
Hi all,
Can any one give details about plug-in models in .NET?
We have an application which will consists of a different documents, which will be displayed in 2 different tree views based on the type of document. and now we are dispatching to our clients. One of clients requires an additional document which is not necessary for others. So we need to implement the plug-in model which will extend the features of such documents. Even the...
|
by: btober |
last post by:
I'm finding that column defaults are not being assigned to nulls when I
do an insert by way of a an ON INSERT rule on a view. For example, the
following script
\set ON_ERROR_STOP ON
\c template1
--DROP DATABASE testdb;
CREATE DATABASE testdb;
\c testdb
|
by: Mujdat Pakkan |
last post by:
We have an interesting case where we want to use Postgres both as a database
and a front end to a proprietary database. For the latter, we wrote
functions that access the proprietary database. Then we defined views on the
proprietary database and wrote rules for insert/update/delete on those views
using the functions. The problem is that we cannot find a way to return
reasonable error values from the access functions. The rules always...
| |
by: Nick |
last post by:
Hi,
I am wondering what people do to achieve a consistent look and feel for
their websites? Does anybody here do anything similar to the Composite View
design pattern, where a view renderer effectively reads a configuration and
builds up the HTML by choosing particular views based on state and other
factors? I am working on an ecommerce site, and there are quite a few
different screens. In the vanilla fashion, the HTML in the aspx forms...
|
by: Ulrich Meis |
last post by:
Hi!
Situation two schemas:
webviews: Contains a set of views with insert rules on them, accessed
via a GUI.
devconf: "Business logic", all the tables, functions, triggers that I
want to restrict access to as far as possible.Preferably, I wouldn't
even grant usage to the schema.
|
by: linq936 |
last post by:
Hi,
I always have an impression that for the following semantics:
#include <something e.g. #include <stdio.h>
Compiler searches it from built-in header search path, on UNIX, it
could be /usr/include, /bin/include.
And for the following semantics:
#include "someting" e.g. #include "mine.h"
Compiler searches it according to the -I command option and the
built-in search path.
|
by: paankhate |
last post by:
Hi,
I have a task at hand to reduce the time taken for search query to
execute. The query fetches records which will have to sorted by
degrees away from the logged in user. I have a function which
calculates the degrees, but using this in the search query slows the
execution and takes about 10 secs to complete which is unacceptable.
Please advice. Your help is much appreciated
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |