Search tutorials
Summary
So to sum up here is what I want to get across (not all of these points were shown in the examples):
- Inheritance is a linguistic level method of code reuse.
- Subclasses (those that extend another class via the extends key word) inherit based on access modifiers set in the parent class (the one being extended).
- Both variables and methods can be inherited.
- In actionscript (and many other object based languages) a subclass can only extend one parent class. In other words, I can't do class Son extends Father, Grandfather where Grandfather is the name of another class. Some languages do support extending more than one class and this is referred to as multiple inheritance if you want to look into it.
- Inheritance chaining is allowed so I could do Class Father extends GrandFather and then Class Son extends Father which would result in Father having the variables and methods of GrandFather and class Son having the variables and methods of both Grandfather and Father.
- Multiple classes can extend the same parent class. So Class Son extends Father and Class Daughter extends Father is fine, but note that while Son and Daughter would share (as in both have) the code inherited from Father, defining a method in Daughter does not mean it appears in Son and vice versa.
So that was a very basic introduction to inheritance. Again, much more could be, and has been, said about this topic. If you want to learn more, there are always people talking about such topics in the forums.
| » Level Intermediate |
|
Added: 2007-12-10 Rating: 9 Votes: 5 |
| » Author |
| Kortex (aka Jeremy Wischusen) is a Flash/PHP developer for myyearbook.com and the lead software architect for the DigitallyU Digital Portfolio Software Suite. |
| » Download |
| Download the files used in this tutorial. |
| Download (7 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!