> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Hans Wichman
> Sent: 22 March 2007 12:39
> To: [email protected]
> Subject: Re: [Flashcoders] Compiling with self-reference
> Importance: High
> 
> Hi,
> this
> class Clarss {
>        var pRoot:Clarss2
>        function Clarss() {
>        }
> }
> class Clarss2 extends Clarss {
>        function Clarss2() {
>        }
> }
> 
> looks like a design error to me. One of the reasons you would 
> use inheritance is polymorphism, and reducing complexity. A 
> super class having to know the type of its subclasses is not 
> good practice. Why not keep the reference pRoot:Clarss? You 
> can stick any subclass in there.

It depends on the circumstances. My main reason for using inheritance is
code reuse: putting common code into ancestors. In my case, I'm not writing
objects for reuse elsewhere. So it seems pretty reasonable to me that all my
objects know about all the other objects. Here's a simplified example of the
structure I'm trying to create:

RootElement extends Element
SimpleBlock extends BlockElement extends Element
TextItem extends ItemElement extends Element

the Element object has a pChildren:Array (empty for items) and
pParent:Element (undefined for Root) property, creating a tree structure.
Each element also has a direct reference pRoot:RootElement to the tree root
(this is the bit that doesn't work).

I think this makes good sense. I could shore it up by adding an additional
layer:

RootElement extends Element
SimpleBlock extends BlockElement extends ChildElement extends Element
TextItem extends ItemElement extends ChildElement extends Element

Here, ChildElement is the one that has the pRoot property, eliminating the
circular reference. But it seems a bit silly to have to add an empty class
just for the sake of a single property.

Danny

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to