 Hey everybody, this is Brian. Welcome to the eleventh Flutter tutorial. I'm hoping we can wrap up classes today. I'm not going to really cover enumerated types because it's kind of a little different, but what we're going to cover today is Mixins. Let me back up. When I say enumerated type is kind of different, it's It's more or less used as a variable. We will cover these in future tutorials, but right now we're going to really cover Mixins. So what is a Mixin and why do we need it? So it says Mixins are a way of reusing a classes code in multiple class hierarchies. To use a Mixin, use the with keyword followed by one or more Mixin names, and then some examples. And I kind of wanted a better description. So a better description is an object-oriented programming language, which is a Mixin is a class that contains methods for use by other classes without having to be the parent of those other classes. So you kind of take inheritance as a fundamental hierarchy, and you break that. And it's not really interfaces with abstraction. It's kind of like just saying, hey, I don't really want to use the whole class. I just want this little part of it, meaning I don't want to really inherit it, and I don't want to have to be tied to it. It's kind of weird. So let's just make our new project here, and this will calculate the sun, moon, and stars. There we go. Go out here. Did my music stop? I think my music stopped. Yep, I'm still listening, Pandora. Thank you for doing that, Pandora. All right, so back to what we're working on here. We are going to make a car. We're going to make a concrete class, and we're going to say IntDoors. Make a getter for this. We're going to make a black car, because why not? Black's awesome. And we want to play music in our car, and we're just going to say, boom, I don't know, just music, whatever. So we've got four doors. It's a black car, and we're just going to play some music. All right, so pretty simple class. Not a whole lot to it. Now we're going to make a truck. I'm going to make this concrete as well, and we're going to say, bull has four by four, because you need that with a truck, especially here in Michigan. Give this two door. We're going to stay a string color. Hmm, I want a... What color truck do I want? Let's make it a red truck. Giant big red monster truck. And we're going to say, void. I'll honk the horn. Why not? So we've got a car class, and we've got a truck class. Now, let's say we want to make a hybrid of those. We want a Jeep. Actually, let's call it an SUV. I own a Jeep for years and years. I loved it. So in this, we're going to import the car class, and we're going to import the truck class. I'm going to make another concrete class called SUV. And we're going to extend the truck. But this time we're going to say, with the car. What the heck? What's that mean? All right, so let's see what we got going on here. Color is inherited as a getter and also as a method. Ooh, I screwed something up here. See, there's color. Oh, yeah, that's why. There we go. Fix that problem. All right, so our SUV here extends truck with car. Hmm. What does that mean? Well, that's interesting. Let's find out. In here, we're going to import the SUV. We're going to say SUV Jeep equal new SUV. And let's just examine this object and see what's we got going on here. You can see how we have colors, doors, four by four. It has a bed and a horn plays the music. It does all the things that we want it to do. So we can actually say, you know, honk the horn. Jeep. Play the music. And let's say we want to print the number of doors and we want to print the color. Let's see what happens here. So we honk the horn. We play the music. We have four doors and it's black. Hmm. Where did it get foreign black from? That's interesting. Well, if we look at this, you can see we're extending the truck with the car. So if we look at the car, the car has four doors and it's black. So that's where it's getting that from. If we flip those around, you guessed it. We're extending a car with the truck. It will now have different properties. You'll now have two doors in red. So that's really how a mixon works. You can kind of piecemeal classes together and use the parts that you want without really having to mess around too much with interfaces and inheritance and abstraction. It's kind of a I'm not a big fan of it, to be brutally honest with you, because as you can see, if you do things in a specific way, you can change the outcome of what you expect. Like, let's flip this back to truck and flip this back to car and then bang. So, you know, you really get some unexpected results sometime now. Some would argue, well, you know what results to expect because of, you know, the way you're ordering things and all that. Let's just for giggles here. I'm actually just going to try this, let's say. I have no idea what to call this industrial. We're going to make an industrial vehicle and we literally are just going to copy this car class here. And we're going to say this is what have we used blue. And we're going to give this like 900 doors. And of course, there's no way to play music in this thing. Let's go back to our SUV. It's funny, I always get this viewer feedback where everybody's like, we actually like watching you make mistakes. We learn from your mistakes. I'm like, you guys are so mean to me. So now we're extending the truck with the car and the industrial equipment. Let's see what this does here. We'll run this. Suddenly it's got 900 doors and it's blue. So the problem here is that it's picking up the last one. Now I'm not sure if that's actually a standard or if that depends on what sort of just-in-time compilation you go through. So if you get a different vendor's just-in-time compiler, it may take the first one and not the last one. So now you've got to actually account for those and make, you know, functions that do that. You should actually say string, color, equal. I have no idea what to make my Jeep here. Lime green. It's like the ugliest color on the planet. And then you should actually say int doors, equal. And we want three doors just because why not? We'll say it's an old Jeep and one door is messed up. Now suddenly we have the way we want it. But you can get some just kind of crazy unpredictable results with Mixins. It's not bad to use them. I don't want to deter you from it. It is an option. A lot of older programmers will stay away from them simply because they like the structure that inheritance gives or, you know, they want to know what an interface is. Or I'm sorry, they want to know that they have everything that's in the interface that you're providing because an interface is a contract. Whereas a Mixins, it's just kind of, you know, wild west, you just do what you want. So I hope you found this educational and somewhat entertaining. We're going to continue on with Dart. I'm trying to plow through these fairly quickly because I really want to get into Flutter. I really think that Flutter is going to take off in the next year or two. And I think it's going to be a major competitor with the other languages out there, especially things like React Native. So if you found this even remotely helpful, go ahead and visit my website and go to tutorials and you can download the source code for this and other tutorials. Click on contact and go out to the Void Rooms Facebook group. There are 1700 other programmers out there. And in case you're wondering, all of the website and everything is funded 100% by your donations. When you look at my dashboard, estimated revenue is $0. I do not have modernization on any of my videos. So if this helped you guys, especially if you're running a business and you're training your people, feel free to donate and help others.