realbasic-nug
[Top] [All Lists]

Re: Design Question

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Design Question
From: Charles Yeomans <charles@declareSub.com>
Date: Thu, 30 Oct 2008 11:17:49 -0400
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <3A251409-3EBD-497B-88AE-365FD9F90498@mac.com>
References: <3A251409-3EBD-497B-88AE-365FD9F90498@mac.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

On Oct 30, 2008, at 10:53 AM, Sam Rowlands wrote:

Is there a way to create a class.parent without having a property on the class?

For instance say I have a class called Engine, then I have an array of Valve classes. The array is a property of Engine.

Engine.Valves()

However now I want the valve to communicate with the Engine, to notify the engine when it fails, do I create a property on the valve class called parent and set that to be my engine, or is there some fancy trick I can use to probe the valve and figure it out?


There are all sorts of ways that you can design this. In this case, you don't have Valves without an Engine, so have the Engine object hold the reference to the Valves.

You can approach the problem of valve failures in at least two ways. One way would be for the Engine to periodically check its Valve objects for a failure state. To approach it in the way that you want, the Engine could provide a callback to each Valve object. This requires some care, because you'll either need to avoid reference cycles, or plan to deal with them.

As for the general question of parenthood, I use the following approach in some time & billing software. It has a Matter class. A Matter can have submatters. A submatter has a Parent property, and the submatter holds a (strong reference) to the matter. When a Matter needs a list of its children, it gets a list of all matters, available as a shared property, and loops over the list, accumulating a list of all matters claiming it as a parent.

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>