00:00So why are interfaces important and when do you want to use them?
00:04That's a really great question,
00:06and you've already seen throughout this experience that one of
00:09the things that are really, really powerful is that it enables us to
00:12treat elements not based on what they are, but based on what they do.
00:17Now, when it goes into the real world,
00:19and for example, maybe you're going to create some sort of application,
00:22or you're going to work with some sort of application that
00:24expects specific functions to be in it,
00:27it makes it really easy for you to work with other people by telling them,
00:30you just have to adhere to this interface,
00:34you could create the five, six characters of the game,
00:36I'll continue building up the game,
00:38I don't have to worry about those characters,
00:40all you have to do is make sure you
00:42implement your elements using this interface.
00:45The same true is for yourself.
00:47So as you build the interface,
00:49now you can move on and build
00:50separate little pieces of your application
00:53without them affecting your larger application,
00:56and you could always continue building the larger application,
00:59and you could always go back to build
01:00the smaller components without needing to worry about the two at any stage.
01:05So basically, as soon as I've created this interface,
01:08as soon as I created my main,
01:09you saw when I added the fire or when I added the cup,
01:12I didn't have to change anything in my main.
01:14My main was ready and working and could deal with all those stuff.
01:17When we added and changed things in our main was just to add more functionality.
01:21But we never had to go into our main just to
01:23add its capability to support more elements.
01:27Now that our main knows how to deal with iPlayable elements
01:30and it knows how to deal with iTouchable elements,
01:32it's more or less bulletproof.
01:34Our only problem here is really in line 17 and 18
01:37where we're hard-coded adding our elements and we're not doing it dynamically.
01:42But that is only because we put all our elements on our stage
01:46and we didn't use addChild and we didn't create them on the fly,
01:49and we didn't do that mainly because we wanted to focus on our topic
01:53and not focus on the bigger picture
01:55because then it would just take more time in our videos.
01:58Now another thing where interfaces are incredibly, incredibly, incredibly powerful.
02:03When you look into the iPlayable, the iPlayable interface is very small.
02:07It takes maybe, maybe, maybe a k-kilobyte of text.
02:13Now contrary to that, our animal, Pritex 1015, our dog takes a lot more than that.
02:18Thus, if we were, for example, loading in external files,
02:23if we were trying to check to see if they're a type of animal,
02:27we would have to have the animal itself baked into our loading Swift.
02:32And if it was loaded into our loading Swift,
02:34our loading Swift automatically would have all these bytes of our animal.
02:38Now imagine that your secondary Swift has updated and has a new Swift.
02:43Now I have bad news for you because if they're working in the same domain,
02:46the same namespace, the same everything,
02:49the first thing that's loaded is the first thing that's going to be in the library.
02:53AKA, your latest version inside of your internal Swift would not work.
02:58Contrary to that, if we didn't work with the classes
03:01that are not needed within the main Swift,
03:03and we only use interfaces there.
03:06Now we don't have to worry about version controlling anymore.
03:09We don't have to worry about file sizes
03:11because we're not going to load in twice the same elements
03:13because they're in different Swift.
03:15All right?
03:16So that's really the two most powerful features of interfaces.
03:20Now with that said, don't overuse interfaces.
03:23Use them as you need them.
03:24In the beginning, I know you might become trigger,
03:27happy to use them a lot, and that's totally fine.
03:29But the big picture in the end of the day as you mature as a developer
03:32is to find that right balance between
03:34when do you want to work with interfaces and when not.
03:37And really, it comes down to experience.
03:40And really, the more you do it, the more you're going to gain
03:43the experience of knowing when to use it.
03:45I'm a fan of always do less.
03:48Do more only when you need to.
03:50Unless you have a big plan.
03:51So if you have a big plan and you already know in advance,
03:53you're going to be building a zoo that has 10 different animals,
03:57but they share functionalities,
03:58you already have your reason for an interface.
04:00If you're going to be working with another person,
04:02you have already a reason for an interface.
04:04All right?
04:05So that covers this title.
04:08I hope you enjoyed it.
04:09This covers our poll from us in second hour.
04:13And hope to see you in our next title.