 Hey, everybody, this is Brian. Welcome to the drum roll. Where are we? We are on the ninth flutter tutorial We're gonna continue our conversation on classes here Did have some interesting feedback from this guy here president President one dart is dead. Why are you doing tuts on this? I actually don't think dart is dead I think darts actually just getting started. I think it's very new and very in its infancy And I'm hoping Google grows it quite a bit. So that is why kind sir I am doing tutorials on this. So we're gonna Continue our conversation about classes if you're trying to follow along with the official documentation We are on extending a class So extending a class use extends to create a subclass and super to refer to the super class What in the heck does that mean? Well, we're gonna cover that over the next three tutorials And I'm gonna do a little bit here. I'm gonna actually cover how to extend the class abstract classes and mixins But we're gonna have to kind of break it up to a few tutorials. So let's just get going with this one here And let's do next Gotta adjust my office chair here. What's up with that? And while that is calculating the meaning of life to everything. I'm gonna actually adjust this chair. Man It's like driving me nuts all right, so what we're gonna look at here is Classes and inheritance and you may have heard of inheritance before in other languages So the first thing we're gonna do here is we're going to make a new dart file We'll call it mammal and in mammal. We're gonna make a class And we're gonna say bull has backbone And we're gonna make another bull has hair because a mammal has to have a backbone and hair There is our beautiful mammal class in all of its glory. So what we want to do now is actually make another one And we're gonna call this feline For all you cat lovers out there, we're going to import the mammal class and we're saying class feline And this is where the extends keyword comes in extends mammal So what have we actually done here? If you are not familiar at all with inheritance and what I'm talking about here is we're extending this class It used to be the keyword used to be in other languages inherit or it was just a semicolon So what we're doing is we're taking the mammal class and actually adding to it or extending it So we're gonna say bull Has claws True because most cats have claws and then we're just gonna make this void test We're gonna say assert You notice how IntelliSense is smart enough to know what's going on here has claws has backbone has hair So you can see the other properties here So we're just going to assert that this has a backbone And we're going to assert That it has hair now what assert does is it actually throws an error message if this tries anything and it doesn't evaluate true So that's just a test function. We're gonna leave in there for now But what we're gonna do is take this even further and Show you that you can do some really cool things with inheritance here So now we're gonna take our feline class that we made we're gonna make a class and call it lion And we're going to say void Roar And let's just do this so tomorrow is Thanksgiving while I'm typing here and I'm actually kind of nervous because I'm cooking a turkey for the first time Yeah, it's gonna be interesting here some people have told me to cook the turkey upside down some people have told me to Not stuff it some people have told me to stuff it some people told me to do all of these Crazy things one person told me to get like a surgical syringe and actually inject things into it I'm guessing that's how you actually like calm down your guests. You just like inject like Some sort of sedative into the turkey All right, so what we're doing here is we've got our test And we've got our roar function now. Let's actually test this whole thing out. Let's get rid of this and let's say Lion Simba, why not? It's actually a spell Simba. Oh well Equal new lion And we're gonna say Simba dot and you notice how bam it has all these other properties here So we can actually Call test we can actually make him roar. Although. I don't think Simba would roar but come on keyboard. You can do it. I believe in you and he's roaring and the tests ran We can actually go back here and this is uh, this is a tricky thing about inheritance Let's say back in the mammal class here. We flip this to you false Then we're gonna say not all mammals have hair because I'm changing everything Well, you can see how felines test is not gonna just explode Lion's test is now just going to explode. So let's run this and see what happens And you see unhandled exemption failed assertion meaning our assert statement evaluated defaults has hair is not true And it's saying line seven Number 12 so there's 712 bam. That's where our issue is right here And then we can kind of do this and you can see how it's in lion test. Da da da da What we can actually try here is Play around with what's called the super class and we can say super whoops Dot test. So what is this actually doing? Super actually grabs the class that you're extending in this case feline And it's going to call test here in feline. So let's actually do this print testing In feline and let's do this print testing in lion That way we know exactly where this is coming from here And you can see how it's testing in lion testing in feline Because this is being called, but then we're calling super dot test, which is actually calling in feline Now this assert function is actually failing right here saying blah blah blah Line 9 12 is not true and we can see how it's calling feline test right here And it gives you the path to the file. I think yep, you can actually click on it It takes you right to it So you can follow this is called a a trail here if you will or a stack trace You can see that it's being called here. It's being called here and finally boom. That's where the air is being called So that is the tricky part about inheritance is if you make something and other people are inherit classes and extend them you can really break a lot of things and so you have to be a little careful and You have to almost not trust what you're extending and that is where overrides come in right So we should just put over right there so we know what we're doing here This is just a declaration telling us that we're overriding this What we could actually do is we could actually put a setter in here and set that to true But I'm not going to mess around with it. I want to leave this as is so you understand the some of the pitfalls That can happen when you're doing inheritance So to kind of recap here We have our lion class the lion herds from feline feline actually inherits from mammal and Let's flip this back to true that way if somebody downloads the code. It's not gonna have an error and I don't get a hundred hate mails So what is mammal really doing here? Mammal is considered the root superclass if you will meaning it's not extending anything else It's just the base class if you will All of these properties then flow up through all of the other things that are inheriting it So that is inheritance in a nutshell Short simple to the point, but a very powerful feature You can do a lot of cool things with this, but you can also paint yourself into a corner. So definitely structure your programs. Well That's it. Thank you for watching. I hope you found this educational entertaining If you're looking for the source code for this and other tutorials go out to my website boydrums.com You got to get hub and download all the source also there is a Boydrums Facebook group with 1700 other programmers out there that can definitely help you if you have any issues