<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ActionScript 3: Handling Inheritance</title>
	<atom:link href="http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 31 Jan 2012 13:51:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Youdgin</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-160</link>
		<dc:creator>Youdgin</dc:creator>
		<pubDate>Tue, 07 Dec 2010 13:51:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-160</guid>
		<description>I have a problem if someone can help. I have a double linked list implemented and for a class ListNode wich has properties next:ListNode and prev:ListNode (wich are instances of their own class) and obj:*. My problem is how do I inherit the class ListNode  let&#039;s say with the class ListGeniNode(that is what actualy i need)  in that way so i can access methods of the child class  through the properties of the parent class. Example:
public class ListNode{
  public var next:ListNode;
  public var prev:ListNode;
  public var obj:*
//constructor goes here
}
public class ListGeniNode extends ListNode{
//constructor goes here
   public function get geniTreeNode():GeniTreeNode{
     return super.data as GeniTreeNode;
   }
}
class main{
   function main():void{
   var node:ListGeniNode = new ListGeniNode();
   node.next.obj = new GeniTreeNode();
   trace(node.(next as ListGeniNode).geniTreeNode);//returns null but not the object GeniTreeNode
   }
}

And i sort of know that you cant cast the parent instance to child but is there a way around this and  any suggestions are welcomed.
The reason is the proper reusing of the Class ListNode(because the getter is available only for GeniTreeNode type objects) and to know what to do if I find similar cases like this. Thank You!</description>
		<content:encoded><![CDATA[<p>I have a problem if someone can help. I have a double linked list implemented and for a class ListNode wich has properties next:ListNode and prev:ListNode (wich are instances of their own class) and obj:*. My problem is how do I inherit the class ListNode  let&#8217;s say with the class ListGeniNode(that is what actualy i need)  in that way so i can access methods of the child class  through the properties of the parent class. Example:<br />
public class ListNode{<br />
  public var next:ListNode;<br />
  public var prev:ListNode;<br />
  public var obj:*<br />
//constructor goes here<br />
}<br />
public class ListGeniNode extends ListNode{<br />
//constructor goes here<br />
   public function get geniTreeNode():GeniTreeNode{<br />
     return super.data as GeniTreeNode;<br />
   }<br />
}<br />
class main{<br />
   function main():void{<br />
   var node:ListGeniNode = new ListGeniNode();<br />
   node.next.obj = new GeniTreeNode();<br />
   trace(node.(next as ListGeniNode).geniTreeNode);//returns null but not the object GeniTreeNode<br />
   }<br />
}</p>
<p>And i sort of know that you cant cast the parent instance to child but is there a way around this and  any suggestions are welcomed.<br />
The reason is the proper reusing of the Class ListNode(because the getter is available only for GeniTreeNode type objects) and to know what to do if I find similar cases like this. Thank You!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Hawthorne</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-159</link>
		<dc:creator>Eric Hawthorne</dc:creator>
		<pubDate>Mon, 18 Aug 2008 23:30:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-159</guid>
		<description>Regarding the original problem.
Look up the terms &quot;covariant inheritance&quot;
and &quot;contravariant inheritance&quot;

O-O programming languages take different points of view on this
issue. Both POVs have merits.

The contravariant case says: Look: I might want to have a setter method on the FruitTree that says e.g. setFruit(f:Fruit).
Now since the proper interpretation of inheritance is &quot;isa&quot; then an AppleTree isa FruitTree, and whatever I can call on a FruitTree, I must be able to also call on an AppleTree. So I call
aFruit:Pear = Pear()
myAppleTree.setFruit(aFruit)
and, according to the contravariant interpretation of &quot;isa&quot;
contracts, that argument needs to be accepted, because it meets
the type criteria on the setFruit method.

Covariant inheritance (of method argument type constraints)
would say no, what we are doing is defining a specialization
hierarchy of whole-part objects and we need structural (part)
specialization when we specialize the type of the &quot;whole&quot;.
So we should allow the setFruit(f:Fruit) method to throw
an &quot;incompatible part type&quot; exception if we send a Pear in
to be part of an AppleTree.

Java takes the contravariant view for method argument type
constraints, but allows covariantly specialized return types
on method return values, which is less controversial, since
a covariant (more specialized type returned by method call
on subclass) still meets the typ constraint specified on the
general class version of the method declaration.</description>
		<content:encoded><![CDATA[<p>Regarding the original problem.<br />
Look up the terms &#8220;covariant inheritance&#8221;<br />
and &#8220;contravariant inheritance&#8221;</p>
<p>O-O programming languages take different points of view on this<br />
issue. Both POVs have merits.</p>
<p>The contravariant case says: Look: I might want to have a setter method on the FruitTree that says e.g. setFruit(f:Fruit).<br />
Now since the proper interpretation of inheritance is &#8220;isa&#8221; then an AppleTree isa FruitTree, and whatever I can call on a FruitTree, I must be able to also call on an AppleTree. So I call<br />
aFruit:Pear = Pear()<br />
myAppleTree.setFruit(aFruit)<br />
and, according to the contravariant interpretation of &#8220;isa&#8221;<br />
contracts, that argument needs to be accepted, because it meets<br />
the type criteria on the setFruit method.</p>
<p>Covariant inheritance (of method argument type constraints)<br />
would say no, what we are doing is defining a specialization<br />
hierarchy of whole-part objects and we need structural (part)<br />
specialization when we specialize the type of the &#8220;whole&#8221;.<br />
So we should allow the setFruit(f:Fruit) method to throw<br />
an &#8220;incompatible part type&#8221; exception if we send a Pear in<br />
to be part of an AppleTree.</p>
<p>Java takes the contravariant view for method argument type<br />
constraints, but allows covariantly specialized return types<br />
on method return values, which is less controversial, since<br />
a covariant (more specialized type returned by method call<br />
on subclass) still meets the typ constraint specified on the<br />
general class version of the method declaration.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-158</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Tue, 18 Mar 2008 18:56:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-158</guid>
		<description>tom, I&#039;m pretty certain that is the correct behavior. As a private constant, MYCONST will always be &quot;A&quot; within class A and that&#039;s where the toString() method is located. MYCONST as specified in class B is a completely different constant that cannot be accessed from class A.</description>
		<content:encoded><![CDATA[<p>tom, I&#8217;m pretty certain that is the correct behavior. As a private constant, MYCONST will always be &#8220;A&#8221; within class A and that&#8217;s where the toString() method is located. MYCONST as specified in class B is a completely different constant that cannot be accessed from class A.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tom</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-157</link>
		<dc:creator>tom</dc:creator>
		<pubDate>Tue, 18 Mar 2008 18:38:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-157</guid>
		<description>ok, here is what I consider a serious bug in the inheritance of as3

class A {
  private const MYCONST:String = &quot;A&quot;;
  public function A(){}

  public function toString(){ return this.MYCONST; }
}

class B extends A {
  private const MYCONST:String = &quot;B&quot;;
  public function B(){ super() }
}

trace( new A() ); // prints &quot;A&quot;;
trace( new B() ); // prints &quot;A&quot; ?!?!?!?!??!</description>
		<content:encoded><![CDATA[<p>ok, here is what I consider a serious bug in the inheritance of as3</p>
<p>class A {<br />
  private const MYCONST:String = &#8220;A&#8221;;<br />
  public function A(){}</p>
<p>  public function toString(){ return this.MYCONST; }<br />
}</p>
<p>class B extends A {<br />
  private const MYCONST:String = &#8220;B&#8221;;<br />
  public function B(){ super() }<br />
}</p>
<p>trace( new A() ); // prints &#8220;A&#8221;;<br />
trace( new B() ); // prints &#8220;A&#8221; ?!?!?!?!??!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryan</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-156</link>
		<dc:creator>ryan</dc:creator>
		<pubDate>Fri, 08 Sep 2006 18:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-156</guid>
		<description>I agree with the interface assessment. I may be missing something regarding the intended usage, but the interface structure is there exactly for the case where you want to pass multiple types around in one place. In conjunction with a superclass, you can then have a class that you can pass around as any of the interfaces that it implements, while still allowing it to inherit common functionalities (or override) from the superclass. Taking advantage of this (or being forced to do this ;) ) also helps force you into thinking a in a bit more organized fashion, which is nice sometimes...</description>
		<content:encoded><![CDATA[<p>I agree with the interface assessment. I may be missing something regarding the intended usage, but the interface structure is there exactly for the case where you want to pass multiple types around in one place. In conjunction with a superclass, you can then have a class that you can pass around as any of the interfaces that it implements, while still allowing it to inherit common functionalities (or override) from the superclass. Taking advantage of this (or being forced to do this <img src='http://joshblog.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) also helps force you into thinking a in a bit more organized fashion, which is nice sometimes&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-155</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Thu, 11 May 2006 18:11:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-155</guid>
		<description>Here&#039;s an interesting solution that is similar to David&#039;s.

//In FruitTree class
protected function initializeFruit():void
{
    this.myFruit = new Fruit();
}

//In AppleTree class
override protected function initializeFruit():void
{
    //AppleTree now includes a myApple variable
    this.myApple = new Apple();
    this.myFruit = this.myApple;
}

It still clutters the class with an additional property, which I&#039;m not a fan of. I&#039;d use this one over David&#039;s to bypass the overhead of calling a function and casting myFruit as an Apple.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s an interesting solution that is similar to David&#8217;s.</p>
<p>//In FruitTree class<br />
protected function initializeFruit():void<br />
{<br />
    this.myFruit = new Fruit();<br />
}</p>
<p>//In AppleTree class<br />
override protected function initializeFruit():void<br />
{<br />
    //AppleTree now includes a myApple variable<br />
    this.myApple = new Apple();<br />
    this.myFruit = this.myApple;<br />
}</p>
<p>It still clutters the class with an additional property, which I&#8217;m not a fan of. I&#8217;d use this one over David&#8217;s to bypass the overhead of calling a function and casting myFruit as an Apple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: george</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-154</link>
		<dc:creator>george</dc:creator>
		<pubDate>Thu, 11 May 2006 15:21:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-154</guid>
		<description>Probably not the best idea, but simple. You can just use a wildcard in myFruit declaration. myFruit:*</description>
		<content:encoded><![CDATA[<p>Probably not the best idea, but simple. You can just use a wildcard in myFruit declaration. myFruit:*</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-153</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Thu, 11 May 2006 03:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-153</guid>
		<description>Actually, that won&#039;t work Mike. It will cause an &quot;Incompatible override&quot; error. That was the first thing I tried.</description>
		<content:encoded><![CDATA[<p>Actually, that won&#8217;t work Mike. It will cause an &#8220;Incompatible override&#8221; error. That was the first thing I tried.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike J</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-152</link>
		<dc:creator>Mike J</dc:creator>
		<pubDate>Thu, 11 May 2006 03:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-152</guid>
		<description>I would actually take Davids example and make it a bit more generic. Haven&#039;t done AS3 yet, but to illustrate:

Class FruitTree {
    private _myFruit:Fruit;
    public function get myFruit():Fruit { ... }
}

Class AppleTree {
    public function get myFruit():Apple {
        return _myFruit as Apple;
    }
}

That way, you can still access it using this.myFruit but it should be cast correctly without adding boatloads of extra code.</description>
		<content:encoded><![CDATA[<p>I would actually take Davids example and make it a bit more generic. Haven&#8217;t done AS3 yet, but to illustrate:</p>
<p>Class FruitTree {<br />
    private _myFruit:Fruit;<br />
    public function get myFruit():Fruit { &#8230; }<br />
}</p>
<p>Class AppleTree {<br />
    public function get myFruit():Apple {<br />
        return _myFruit as Apple;<br />
    }<br />
}</p>
<p>That way, you can still access it using this.myFruit but it should be cast correctly without adding boatloads of extra code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://joshblog.net/2006/05/10/actionscript-3-handling-inheritance/#comment-151</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Thu, 11 May 2006 03:05:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.zeuslabs.us/archives/64/actionscript-3-handling-inheritance/#comment-151</guid>
		<description>That&#039;s an excellent example, Todd. It shows why a developer would want to use interfaces (something many have trouble understanding right away), and it helps illustrate how one can abstract an action (such as removing a stem) into a more generalized form (like preparing the fruit) so that it can be used across many different kinds of related objects. You should post it on your blog. I&#039;m sure a lot of people could benefit from it.

I&#039;m currently migrating a good deal of code (probably a hundred classes or more) from AS2 to AS3. Building the original code, I ran into many situations just like that, and I used similar solutions. Some objects have more obvious connections than others, obviously. I&#039;ll have to spend some time looking for nice generalizations like that. Now&#039;s probably the best time to do it, too, since we&#039;re working on such a big transition.</description>
		<content:encoded><![CDATA[<p>That&#8217;s an excellent example, Todd. It shows why a developer would want to use interfaces (something many have trouble understanding right away), and it helps illustrate how one can abstract an action (such as removing a stem) into a more generalized form (like preparing the fruit) so that it can be used across many different kinds of related objects. You should post it on your blog. I&#8217;m sure a lot of people could benefit from it.</p>
<p>I&#8217;m currently migrating a good deal of code (probably a hundred classes or more) from AS2 to AS3. Building the original code, I ran into many situations just like that, and I used similar solutions. Some objects have more obvious connections than others, obviously. I&#8217;ll have to spend some time looking for nice generalizations like that. Now&#8217;s probably the best time to do it, too, since we&#8217;re working on such a big transition.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

