Sam Rowlands' NotificationCenter is Awesome!

Hey all,

I wanted to give a public shout-out to Sam Rowlands for his excellent NotificationCenter code in the September/October 2014 issue of XDev Magazine. Someone recommended this to me a couple months ago and it has been an absolutely fantastic tool and an eye-opener for me as well.

I’ve come to realize that this little piece of code can greatly simplify things in my code. So for example, in the past, if I wanted to send an update of some data to a number of different objects, I’d start a for/next loop and loop through all the different objects and set the value. This is fine if all the controls are on the same page or window. However, if you want to update other windows or do other crazy things, it can get messy. Plus every time you want to do this, you have to create these for/next loops.

Not any more. Now, I just package up what I want to send and send it to the NotificationCenter. Boom! It has all the loops and takes care of getting everything to the correct place.

I’ve found that where I want to isolate the UI from the backend code - this is absolutely fantastic. This is particularly true in Web Apps where you may have multiple clients. I just started to implement NotificationCenter in my Web app for something simple. Then as I dug into it, I was like, “Hey - I can do this with it.” Then it was like, “Oh wait - I can use it for this too.” Now, I have begun to heavily utilize it. All my UI interactions are now passing messages to the notification center which is then handling all the backend processing. Way cool. This is great with multiple web clients. Now, each page that opens up, registers in the NotificationCenter. So instead of having to keep track of each page being added or removed in the App objet and then looping through an array of pages to update various controls or values, I now send it all to the notification center. Now all my pages update automatically. I’m finding I’ve removed quite a few lines of code.

And what else is cool, is something like this is totally helping me to see how to do a better job of OOP.

So thank you Sam for your excellent work! If I ever get to a XojoDev conference and you are there - I owe you a few adult beverages… :slight_smile:

If you have not checked out this nifty module, I highly recommend you do so. It will save you tons of time. And it is well worth the money you will pay for the XDev issue if you are not a subscriber.

Now, if I can just find more time to read my XDev subscription, I’d probably find many more gems in there…

2 Likes

Some days ago I was searching my HD for exactly this article/example project, but I did not remember who wrote it, where I read about it and how it was named. So Jon’s post here is quite fantastic, just comes at the right moment!

http://www.xdevmag.com/browse/12.5/12504/index.shtml

1 Like

Yeah, this is quite awesome. Really helps when trying to decouple objects. I plan on relying on hit very heavily in the future as time goes on…

1 Like

Really pleased to hear that it helps, everything we build now is based upon this structure. Make life (and debugging) so much easier.

1 Like