Casting and DataTypes
Casting and datatypes go hand in hand and although we met this concept a few times since we started our training it was a good time to look at it one more time as using casting and data-types we are creating polymorphism. In this short video we talk more about why you would want to do this and the steps involved. We go into a few real world examples of where this could be come very useful.
Video Transcript
00:00Welcome back to our second hour we're talking about interfaces and what we were
00:05basically we're going to be doing pull from as into the next hour we're not
00:09going to be calling it each time anymore we're going to define only one more
00:12time before we move on so I wanted to kind of like do a really quick recap of
00:18what we've learned in the last hour so what I want you to do is open up your
00:22flash file and just go into your properties make sure that you have the
00:26latest files from the last course that was just completed and go into the main
00:32file into the main class in our main class we're going to see that and I'm
00:36going to just jump right and highlight this area is the on click event now
00:41notice that in line 10 what we did in the last course is we're just listening
00:45to the stage at for anything that's being clicked on and thus only when
00:49sending is getting clicked then we're checking to see what is it now you
00:54might not have not of wanted to do this in this example like this but imagine
00:59that you have some sort of a zoo and each time to someone that clicks on that
01:03specific animal then you want a different behavior based on a category of
01:07animals and not based on a specific animal and that you know it's just one
01:11idea there's so many ideas when it comes into this idea of polyformism now
01:15really to lock in the concept of polyformism what we're doing here is
01:19we're doing something that's called casting and we didn't have to cast it
01:24and immediately use it but basically if we wanted to and I just want to show it
01:27to you an example here I could have created just a new variable and I could
01:32have called this variable let's say touch and this touch could be of type
01:36I touchable and then I could put the value basically of can basically casting
01:46the value that I'm getting back from my target in my event into that variable
01:50now you you want to notice that not always what we're going to get back is
01:55I touchable it could be saying that's not touchable such as our fire right now
01:59which isn't touchable and thus creating this variable in our case is not needed
02:04but if we would put here more actions there are more things that would go on
02:07then setting up a variable in this format would probably be a good idea and
02:11then we could just approach this variable for now on and really this is
02:14the dictionary definition of polyformism because we don't really know
02:18what type of object this is this could be a cat it could be a dog and
02:21and as we've learned in our last video it could be a cup of water as well
