473,581 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Iobserv able)).
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 SupportMaintain er();

myModel.AddObse rver((IObserver ) this.dataGridFa ilures);

myModel.AddObse rver((IObserver ) this.dataGridMe ssages);
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 InitialieCompon ent()
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 6449
"Marcel Hug" <ma************ ******@ATch.abb .com> a écrit dans le message de
news: Oi************* @tk2msftngp13.p hx.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
InitialieCompon ent()
| 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 InitializeCompo nent() 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
InitializeCompo nent().

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
2713
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 points to online tools and tutorials. Python related news and events will also be reported upon. This podcast series will probably not be of much...
6
6106
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 runtime). Does it indicate a problem with References for example? Thanks Owen PS. replies cc'd by email appreciated....
2
2142
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 before and have no idea how to do it). Now these online forms will be shared by 1200 users. VB and ASP will be used as glueware for the...
15
6735
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 javascript or vbscript it works. I will appreciate any help. I do the following (C#):
2
3772
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 ). Now, i want to show an advertisement on top of each of this html page. the ad banner has to be dynamically updated depending on date (period) the...
2
4555
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 easy, but 1) How do I set about dynamically creating user controls (like TextBox, TextArea) --- simply Declare and initialised (new) the user...
0
2126
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 really fine. No problems at all. But, when this control is placed inside a template of an Infragistics UltraWebTab control, somethings stranges...
9
2969
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
1368
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, classic class and property differences involved. So can somebody please explain to me why this works (using a classic class): class C: TheEvent...
1
3476
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 when condition matched? Also how to present event was used/observed by other observer?
0
7789
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...
0
8301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7894
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...
0
8169
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 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...
0
6551
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
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
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.