Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 22.4 ('Spy On Your Variables')
Instant purchase and download via GumRoad!

FEATURE

Design Patterns Part 5

Using the Observer Pattern

Issue: 22.4 (July/August 2024)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 16,596
Starting Page Number: 26
Article Number: 22404
Resource File(s):

Download Icon project22404.zip Updated: 2024-07-01 10:15:30

Related Link(s): None

Excerpt of article text...

Today, I'm continuing my series on design patterns in Xojo, and I'm going to write about the Observer pattern. This was part of my talk at the MBS Xojo conference in Andernach, Germany in April.

The Observer is a fun pattern and one I've needed in decades past, so I know I'll be using it often in future projects.

A Watchlist for Variables

Have you ever had a situation where you wanted to know when a particular variable changed? This is a common need where one part of a program—possibly a user interface element—needs to know when a particular property's value changes so it can update its display, enable a control, or perform a relevant action.

You could, of course, check the value periodically with a timer, but that's not always the best use of resources, especially if the item doesn't change often. It also will only update as often as the timer runs. Wouldn't it be better if the variable itself could notify you when it changes?

This is where the Observer pattern comes in. It's basically a notification system for variables. Even better, it's dynamic and can be changed at runtime. It also works with unlimited objects.

...End of Excerpt. Please purchase the magazine to read the full article.