473,398 Members | 2,088 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,398 software developers and data experts.

Creating MVC with Observer-Pattern

Hi NG !
I have already written a task about MVC and I tried to get the best
informations together.
I would like to implement the MVC pattern and it work on the way I did it.

At first i know the MVC-ipmlementation from the JAVA by using the
observer-pattern.

I used an interface IObservable (AddObserver, RemoveObserver,...). My Model
implemented this interface.
I created a second interface IObserver (Update(Iobservable)).
I have to datagrids, which have to show the content of correpsoning datasets
in my model, which would be updated by user interactions.

So i created 2 classes (one for each grid), which extends from DataGrid and
implements IObserver.
In my dump mainForm i designed my to datagrids.
In the constructor i used the following code:

IObservable myModel = new SupportMaintainer();

myModel.AddObserver((IObserver) this.dataGridFailures);

myModel.AddObserver((IObserver) this.dataGridMessages);
Now my questions:

1.) In order to run the program i have initialized my designed datagrid with
my two classes (which extends) from datagrid.
It works good, but I have done this initializing in the InitialieComponent()
Methode, which should not be edited in the editor (summery-remark). Is it a
"illegal" way to do this, like i did ? Why should this code not be edited ?.

Would it be better to create UserControls for my datagrid classes
(Observers) ?

2.) Is there a possability to use my classes in the form without creating
usercontrol. I guess not by using the designer !?!

Thanks and regards

Marcel
Jan 4 '06 #1
1 6432
"Marcel Hug" <ma******************@ATch.abb.com> a écrit dans le message de
news: Oi*************@tk2msftngp13.phx.gbl...

| I have already written a task about MVC and I tried to get the best
| informations together.
| I would like to implement the MVC pattern and it work on the way I did it.

Marcel, you seem to be intent on adding the Model and Controller to your
form class.

This is not how MVC is intended to work; the whole idea of MVC and its
successor MVP, is to separate UI functionality from business model
functionality via a Controller. That Controller should not be a part of the
View (form), it is meant to hold a reference to both the Model and the View;
the way you are doing it, the View has a reference to the Model and
Controller.

| Now my questions:
|
| 1.) In order to run the program i have initialized my designed datagrid
with
| my two classes (which extends) from datagrid.
| It works good, but I have done this initializing in the
InitialieComponent()
| Methode, which should not be edited in the editor (summery-remark). Is it
a
| "illegal" way to do this, like i did ? Why should this code not be edited
?.

It is not "illegal" to alter the InitializeComponent() method, but it is not
wise so to do as the IDE manages this code and could scrub any alterations
you make. You should amend the constructor, just after the call to
InitializeComponent().

Better still, if you followed the correct way of implementing MVC, you
wouldn't need to write any code at all in the form class.

| Would it be better to create UserControls for my datagrid classes
| (Observers) ?
|
| 2.) Is there a possability to use my classes in the form without creating
| usercontrol. I guess not by using the designer !?!

If you have derived from DataGrid in order to implement the Observer
pattern, then you don't need any other classes on the form. Create a module
for the Model and another for the Controller, do all the work in those.
There is absolutely no point at all in implementing MVC within a form class,
it just doesn't make sense.

Joerg also suggested that you don't need to implement MVC as the data-aware
nature of .NET controls removes a lot of that requirement. Hµowever, if you
insist on using MVC for a learning experience, then you should not use the
"classic" implementation using the "classic" Observer pattern, instead you
need to use a modified pattern that takes advantage of things like multicast
delegates, etc that .NET provides.

Take the example of the ISubject or IObservable interface; all it does is
maintain a list of IObservers and broadcast a call to an Update method. This
can be replaced by the following interfaces :

public interface ISubject
{
event EventHandler Notify;
}

public interface IObserver
{
void Update(object sender, EventArgs args);
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Jan 4 '06 #2

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

Similar topics

2
by: rdsteph | last post by:
Python411 is a series of podcasts about Python, aimed at hobbyists and others who are learning Python. Each episode focuses on one aspect of learning Python, or one kind of Python programming, and...
6
by: owen | last post by:
Generally speaking, what does it mean when I see a "button" with red text showing this message instead of the control I've dragged onto the web form in Design View.? (But the page works fine at...
2
by: Pawan | last post by:
Hi Guys, I have this current assignment where I have to develop online forms for local municipal authorities. I have to use adobe acrobat to create online forms from PDFs (which I have never done...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
2
by: LIN | last post by:
Hello, Greetings. I am creating a web site which will contain lot of articles. I had been planning to create simple HTML page on the server everytime i posted a article (eg. article12.html )....
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
0
by: Ravi Ambros Wallau | last post by:
Hi: I've created a custom control - a grid that uses Infragistics to display some filters, the grid itself, and some buttons. Well, when using this control directly on WebForm, everything works...
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
2
by: Anders Dahnielson | last post by:
Sorry if this is a somewhat silly question... I'm using the Observer implementation found in 'Patterns in Python' and find it really neat. But, I have not yet fully groked the new-style class,...
1
by: john_woo | last post by:
Hi, I'm using prototype 1.6 for observer/attachEventHandler, like Event.observe(myDivId,'mouseup', myFunction); I'm wondering how to remove or stop (or activate/deactivate) this observer...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.