Re: Listing objects



Peter Fox wrote:
Following on from Lüpher Cypher's message. . .
Hi,

Suppose we have a hierarchical class structure that looks something like
this:
Sorry, I lost the plot half way through.

Your objects can be
1 - nesting : object has a 'what are my children' and 'who is my parent' functionality.


2 - pointing : eg object has a 'these are my siblings' or 'previous/next' functionality

3 - dictionary entries : object in some container is discoverable by name


It is more of a [1] and [3] :)
[1] for I do have a tree-like structure of objects. I have $parent (for all objects) and $owner (for objects that are of subclasses of some class) properties so, I can go bottom-up. I also do have children array for objects that have owner so, I can go top-down.
[3] for I am trying to have a global associative array that has unqiue object names as keys and object references as values.


Variations and combinations of course apply. BUT every object exists in some context. I /think/ you might be trying to get A's to point-to/own B's where more than one A could be the parent of a B. Eg
"Sally is daughter of Jean"
"Geoffrey is son of Teddy"
"Sally is daughter of Teddy" // Only one Sally! J+T are married.


In this case[1] create an array of children and point to elements in that array from your parent objects.

eg $child['Sally'] = new ChildObj(.....);
then $Jean->AddChild('Sally') // just a key name or index
or $Jean->AddChild($child['Sally']) // inside the routine do $myKids[] = & $NewChild
where $NewChild is the function argument.


[1] If in this example children can be parents then you should be looking at a single universal 'person' class with the necessary links.


I do have a universal class :) Say,

class Object
   var $name;
   var $owner;
   var $children[];


Now,

class A extends Object
class B extends Object

A's can be owned by A's and/or B's, B's can have many A's and/or B's
B's can be owned by A's and/or B's and can have many A's and/or B's as well.

One of the things I am trying to do is to have global references to all Objects:

global $objects;
$objects = array();

function Object() {
   global $objects;
   ... assign name ...
   $objects[$this->name] = &$this;
}

However, if a property of some Object changes, $objects[$object_name] still has the "old" object. I assume $objects[$object_name] does not reference the object then, rather has a copy of it. So far I was unable to solve this.. By the way, this will work:

$obj = new Object();
$objects[$obj->name] = &$obj;

if it is executed outside any function and any class..


luph .



Relevant Pages

  • Re: Scope of Variant / Array
    ... Even though you declared the array "public" in the main (parent) form, ... a form code module is the same as a class module. ... Constants, fixed-length strings, arrays, user-defined types and Declare ...
    (microsoft.public.access.formscoding)
  • Re: Forth Machine software emulation
    ... ' man is doer \ man has been defined earlier ... but I also want the parent to give ... SWAP CELLS +; PARENT array ...
    (comp.lang.forth)
  • Re: [PHP] unset in foreach breaks recrusion
    ... You are right that my example would only return one entry for each parent. ... of the array that the reference to it, ... (although I've been working with PHP for at least 3 years), ... Thanks for the answer, the none recursion function is a good idea, ...
    (php.general)
  • Re: TImage initialisation & display
    ... Any Delphi TComponent object (or it sdescendant which TImage is) has two ... object) and Parent. ... sends the child's messages (including ones to display itself, ... ALeft // Left of the array of images ...
    (alt.comp.lang.borland-delphi)
  • Re: TImage initialisation & display
    ... Any Delphi TComponent object (or it sdescendant which TImage is) has two ... object) and Parent. ... sends the child's messages (including ones to display itself, ... ALeft // Left of the array of images ...
    (alt.comp.lang.borland-delphi)