views:

219

answers:

2

I've heard of events and SO answers "bubbling up", but what has all that got to do with bubbles?

+3  A: 

If you are asking about the term, I guess it is an analogy to an event 'bubbling' up to the top, like an air bubble does in liquid.

If you are asking what event bubbling is it is an event that is caught by one object that will refire it to any other objects that are listening to it.

To quote a good article here

... a technique called event bubbling that allows a child control to propagate events up its containment hierarchy. Event bubbling enables events to be raised from a more convenient location in the controls hierarchy and allows event handlers to be attached to the original control as well as to the control that exposes the bubbled event.

johnc
+12  A: 

Event bubbling is the idea of information moving up through a deep structure, when proper design dictates that normally information should only flow downward.

In very basic terms, think of a single object. Properly designed, this object should only know about its own child objects. It should have no direct interaction with its parent. Its children and parent objects, in turn, should follow the same rules. In effect, this means that information can only flow downward - a parent can invoke a method, send data into or extract data from its child, but the child cannot forcibly do the same to its parent.

Think of what happens when you blow an air bubble underwater - you don't have to push the air towards the surface - you simply release it and it moves on its own. The same concept applies to event bubbling - deeper controls simply "release" their information - usually via an event - and it "floats" up the chain without directly invoking anything.

With regard to a website like Stackoverflow (or practically any kind of site), the concept of bubbling is the same. Obviously each individual post ought not directly put itself on the home page, but when a single post has been updated, that event is released from the deepest point in the hierarchy - a single post - and floats up to eventually the top level, where it is dealt with (choosing whether or not to display on the home page).

Rex M
Very succinct answer.
Kirk Broadhurst
@Kirk, it's a *good* answer, but I think your definition of succinct differs from mine :-) Succinct would be "events or answers rise to the top effortlessly, like air bubbles in water".
paxdiablo
@Kirk @Pax I was thinking the same thing :) I appreciate the compliment but even I wish this answer was shorter. Sometimes I get carried away with my explanations.
Rex M
@Rex No no! Your answer was amazingly well-written. I'm currently trying to teach programming basics to my girlfriend and your analogies inpired me! I feel like going for a piece of paper and a pen =)
Camilo Martin
+1 for the clever analogy
Chris Ballance