473,395 Members | 1,343 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,395 software developers and data experts.

Bubbling Events

Hello,

I am aware that in ASP.NET there is the concept of event bubbling. What I am
after is some advice on achieveing the same thing in a standard application.

Say I have 3 classes. View, Controller and Model.

View calls Controller and then Controller calls Model.

I would like Model to raise events which the View can handle.

What is the best practice way to achieve this? Should i just raise the event
in Model and then re-raise it in the Controller? Or is there a better way?

Thanks
Paul
Sep 22 '08 #1
5 1530
On Mon, 22 Sep 2008 12:08:04 -0700, Paul <Pa**@discussions.microsoft.com>
wrote:
I am aware that in ASP.NET there is the concept of event bubbling. What
I am
after is some advice on achieveing the same thing in a standard
application.

Say I have 3 classes. View, Controller and Model.

View calls Controller and then Controller calls Model.

I would like Model to raise events which the View can handle.

What is the best practice way to achieve this? Should i just raise the
event
in Model and then re-raise it in the Controller? Or is there a better
way?
I suppose that depends on your interpretation of the MVC design pattern.

You certainly can use the controller as a proxy as you suggest, forwarding
events from the model to the view. In that design, the view would be
aware of the controller and would subscribe itself to the events in the
controller.

An alternative would be to have the view implement some interface that
includes event handlers, and have the controller simply subscribe those
event handlers to the model's events.

Of course, I'm speaking generalities here. I understand that there's an
actual MVC framework in ASP.NET, and it's possible that there's some sort
of pre-defined convention in that framework you could follow.

I don't know anything about that particular part of .NET though, and this
isn't the best forum for ASP.NET questions (my understanding is that there
is in fact an ASP.NET-specific newsgroup). If you want an answer that is
truly ASP.NET-specific describing how the ASP.NET behavior would be
implemented outside of ASP.NET, you should probably post your question in
the ASP.NET-specific newsgroup.

Pete
Sep 22 '08 #2
sorry maybe using MVC was a bad example. Lets just say it 3 classes in a
hierarchy. The class at the bottom is the event raiser. The class at the top
must handle the events...but it can only talk to the middle class. And the
middle class can only talk to the bottom class. It's not asp.net.

"Peter Duniho" wrote:
On Mon, 22 Sep 2008 12:08:04 -0700, Paul <Pa**@discussions.microsoft.com>
wrote:
I am aware that in ASP.NET there is the concept of event bubbling. What
I am
after is some advice on achieveing the same thing in a standard
application.

Say I have 3 classes. View, Controller and Model.

View calls Controller and then Controller calls Model.

I would like Model to raise events which the View can handle.

What is the best practice way to achieve this? Should i just raise the
event
in Model and then re-raise it in the Controller? Or is there a better
way?

I suppose that depends on your interpretation of the MVC design pattern.

You certainly can use the controller as a proxy as you suggest, forwarding
events from the model to the view. In that design, the view would be
aware of the controller and would subscribe itself to the events in the
controller.

An alternative would be to have the view implement some interface that
includes event handlers, and have the controller simply subscribe those
event handlers to the model's events.

Of course, I'm speaking generalities here. I understand that there's an
actual MVC framework in ASP.NET, and it's possible that there's some sort
of pre-defined convention in that framework you could follow.

I don't know anything about that particular part of .NET though, and this
isn't the best forum for ASP.NET questions (my understanding is that there
is in fact an ASP.NET-specific newsgroup). If you want an answer that is
truly ASP.NET-specific describing how the ASP.NET behavior would be
implemented outside of ASP.NET, you should probably post your question in
the ASP.NET-specific newsgroup.

Pete
Sep 22 '08 #3
On Mon, 22 Sep 2008 13:00:14 -0700, Paul <Pa**@discussions.microsoft.com>
wrote:
sorry maybe using MVC was a bad example. Lets just say it 3 classes in a
hierarchy. The class at the bottom is the event raiser. The class at the
top
must handle the events...but it can only talk to the middle class. And
the
middle class can only talk to the bottom class. It's not asp.net.
I don't see how the re-framed question changes my response. My response
was generic in the first place, necessarily ignoring the ASP.NET details
(because I don't know anything about them).

I only mentioned the ASP.NET-specific stuff in case you were looking for
something that specifically follows an ASP.NET model. If you don't care
about that, then hopefully my previous reply is useful as-is.

Pete
Sep 22 '08 #4
hi

sorry. what im asking is what is the best practice way (if there is one) of
getting the events from the bottom to the top.

As i see it i could...

(1) have events raised at the bottom and handled in the middle and then
re-raised in the middle and handled again at the top. this seems like
duplication of effort and like re-throwing exceptions im not sure if it is
frowned upon or not.

(2) i could pass the event around from the middle to the bottom. again im
not sure if i like the idea of passing events around. im not sure if this has
impacts from a thread safety / overhead standpoint.

"Peter Duniho" wrote:
On Mon, 22 Sep 2008 13:00:14 -0700, Paul <Pa**@discussions.microsoft.com>
wrote:
sorry maybe using MVC was a bad example. Lets just say it 3 classes in a
hierarchy. The class at the bottom is the event raiser. The class at the
top
must handle the events...but it can only talk to the middle class. And
the
middle class can only talk to the bottom class. It's not asp.net.

I don't see how the re-framed question changes my response. My response
was generic in the first place, necessarily ignoring the ASP.NET details
(because I don't know anything about them).

I only mentioned the ASP.NET-specific stuff in case you were looking for
something that specifically follows an ASP.NET model. If you don't care
about that, then hopefully my previous reply is useful as-is.

Pete
Sep 22 '08 #5
On Mon, 22 Sep 2008 13:30:01 -0700, Paul <Pa**@discussions.microsoft.com>
wrote:
sorry. what im asking is what is the best practice way (if there is one)
of
getting the events from the bottom to the top.
Out of context, it's my opinion that describing a "best practice" isn't
possible. There are surely situations where proxying makes a lot of
sense. That said...
(1) have events raised at the bottom and handled in the middle and then
re-raised in the middle and handled again at the top. this seems like
duplication of effort and like re-throwing exceptions im not sure if it
is
frowned upon or not.
I think if you can avoid this, you should. You won't always be able to,
but you're right that it involves extra overhead.
(2) i could pass the event around from the middle to the bottom. again im
not sure if i like the idea of passing events around. im not sure if
this has
impacts from a thread safety / overhead standpoint.
You can't pass an event. It's not something that is instantiated,
referenced, etc. So obviously this approach is not valid.

A third approach, one I mentioned before, is valid: having the middle
class subscribe a method of the top class to an event of the bottom
class. This would rely on either the top class exposing the handler
publicly, or having the top class provide a delegate instance (perhaps via
a property or method that returns the delegate) that can be attached to
the bottom class's event.

It's not a perfect metaphor, but I think of this third approach as being
more of a "push" approach, and the first approach as being more of a
"pull" approach. That is, in the third approach, the middle class is
pushing events onto the top class. In the first approach, the top class
is pulling events from the middle class.

So, if you have a preference between "push" and "pull", that could help
guide your design decision as well.

You could in fact implement an intermediate design in which the top class
explicitly passed a delegate instance to the middle class, rather than
waiting for the middle class to ask it for one, and then relied on the
middle class to subscribe that delegate instance to the bottom class's
event. In that respect, the top class is doing a bit of pulling by
driving the subscription process, while still allowing the middle class to
do a bit of pushing (by taking care of the subscription to the actual
event).

Pete
Sep 22 '08 #6

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

Similar topics

1
by: john | last post by:
I1. notice that if you have an onclick event for both the document and for a particular element, the onclick for the element is called first and then it bubbles up to the one for the document. Is...
4
by: Andy | last post by:
Alright, I am beyond confused here and need some guidance. I need a C# only sample. I have a simple Page and within it i am creating a user control (ascx). The user control contains textboxes,...
4
by: Wee Bubba | last post by:
the following event handler checks to see if any parent control has attached to the event 'SearchItemSelect'. i use it for event bubbling whenever one of my search items has been selected and at...
7
by: comzy | last post by:
I have created an event bubbling for my pager control which is used for implementing paging in data grid. Althoug it worked very fine in .NET 1.1 it is throwing the following error after i migrated...
9
by: pamelafluente | last post by:
Hi guys, After the Exception question, I have another one, strictly related. I would also like what is your preferred device to bubble a message (not by exception) to the user Interface. ...
5
by: vbgunz | last post by:
I tested the following script in Konqueror 3, Safari 3, Firefox 2 and Opera 9. All browsers work as expected and all browsers are exactly the same in there results. I have 3 peculiar problems I...
5
by: Zaxxon21 | last post by:
I'm basically trying to implement a simple drop down menu list for a button that I have. When the user hovers over the button, I want a list of button options to appear below the button. If the...
2
by: alhalayqa | last post by:
hi, in MSIE, you can attach onclick event to both anchor and document objects. here is some code : document.onclick = function() {alert('document clicked ...'); } <a href= " " ...
1
by: m.bagattini | last post by:
Hello folks, I'm in trouble with an application using methodologies in subject. The idea is to have a single-page application. The host aspx page coordinates all visualizations, loading and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
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.