AS3 Interface Inheritance
Lets learn the last thing we are about to learn in regarding interfaces in this title. This is the last thing you need to know about as3 interfaces that can become really helpful. Just as much as classes can extend other classes so can interfaces extend other interfaces. In this video we are going to show this in action how an interface and extend another interface and how it effects our code. All the core rules of inheritance in AS3 are applied to interfaces as well and as such this will be a short title. The good news is that our learning of inheritance in earlier titles made this a really easy task.
Video Transcript
00:00Alright, so let's learn our last thing that we're going to learn in the concept of interfaces.
00:04This is the last thing you need to know about interfaces that could become really helpful.
00:09So just as much as classes could extend others with object-oriented programming with inheritance,
00:17so do interfaces.
00:19Interfaces could actually extend other things.
00:22And we're going to show this really, really quickly because it's very simple and it's
00:25very similar to objects, although probably more complicated because this level of inheritance
00:30is a little bit different.
00:32Now what we're going to do is anything that is playable necessarily is touchable.
00:38We're just going to define it.
00:40Not everything that is touchable is necessarily playable, but everything that is playable is
00:44necessarily touchable.
00:46And as such, I playable will extend, extends I touchable.
00:54And that's all we have to do.
00:55So now basically what that means that whatever implements I playable must implement I touchable
01:01as well.
01:02And if we open up I touchable, so if I open up the directory, I touchable, we'll see that
01:07I touchable just has the function touch, I playable has play and stop, thus anything
01:12that implements I playable must implement play, stop and touch.
01:17And thus in our fire scenario where we have I touchable and I playable, where it implements
01:22both, it won't give us an error.
01:23We could definitely do that.
01:25It's still fine, but we don't have to, because now as soon as we define it as implements
01:30I playable, it automatically is implementing I touchable.
01:34And as such, our main whenever it's checking to see if our element where is that if we
01:39look at our on click event itself in our code, we'll see that we're that we had there
01:44our check if our target is I touchable, it is although we're not defining it directly.
01:50But because we are I playable, we are I touchable as well.
01:54Alright, so if we run this again, we'll see that our fire will still be touchable.
01:58And that's all the change we did.
02:00We're not going to dig further into this, because it's a very simple concept that really,
02:05you only really once in a very blue long moon see its actual value because you actually
02:10use interfaces very sparingly.
02:13So using interfaces with inheritance is probably less common.
02:18But yet an important concept to know about and to be able to say that you know everything
02:21you need to know about poly from ism and interfaces.
02:25And if you want to stop right now, you already know everything you need to know about
02:29poly from ism and interfaces, we're just going to have one little extra bonus track
02:33in the next video, that's going to show you another scenario of implementing it in
02:38a very, very cool way.
