 This video was brought to you by my patrons. Thank you so much for your support! Hello there! In object-oriented design there is a principle that states that you should favor composition over inheritance. And I just faced one of these problems where I favored inheritance and now I will have to migrate to composition. And there is no problem on that, but I want to show to you how you can do that using Godot node system. So I have here a black hole which is basically a hole where when the character reaches this area it will be killed. So I just refractoried it. We can see here how I refractoried it. I moved some of the responsibilities that was in this black hole class to other classes so now it is a composite of other classes. So it now has a killing area instead of a 2D area called singularity because they basically do the same thing but now it's just a specific component of this black hole class. I also moved some polymorphism that I was using. There is no need for that because now I have this level on black hole tree entered method. And there is where I want to make the treatments for when the black hole enter the scene. And then I have a problem because back then I was checking for if the node that just entered the tree is of a black hole class. And the problem with that is that I want to shallow my class hierarchy by removing this black hole class. There is no need for it anymore. So instead I will check for what this class has. So what are the components of this class and try to understand if it is or not a black hole. Often the favorite composition over inheritance principle states that you should use components instead of specializing a class. But now I'm trying to use the same principle to type checking. So I'm trying to instead of checking if something is of the type black hole. I will check for if something has what I think that a black hole shall have. So I think that what make up a black hole. And in this case it's a killing area which is basically it's singularity and a gravity. And I have these nodes there. So I will show to you how you can favor composition over inheritance at the type checking level. So let's go back to grow here. And I have this note here. Let me take this. I have this note here. And here I check for you can see that I have a constant. And one of the problems that you have when you make type checking and you favor inheritance over composition is that you will be coupled to a very specific class instead of generic components. So here I am coping this this level class with a black hole class. And now I will have to remove it. And if I favor composition back I wouldn't have to make this refactoring now. So I will go here where I make this check what is it here. And I will do the following. Instead of checking for if this node is a black hole. I will make this. If this node has a node called gravity which is something that the black hole has. So here we have the gravity here. And this node has a node called killing area which a black hole also has. So we can see a killing area. Then it will be a black hole. So this is what a black hole means in the context of my game. And to check that if this is working I will make the following. I will decrease the black holes falling time. Something more testable. So just one second. Two seconds. And let's try this out. So we have this break point here. And let's see. I will take rid of this and test this again. There is the black hole. Not the black hole. And they are all pushing out pulling the little mouth. So you can see that it is working and I can now take rid of this here because I don't need it anymore. I think that I can take rid of the astromouse as well because I made the same approach here. So the only node that has actions in my context is the astromouse. So I can make this treatment properly. So that's it. This is my tip for you. Favorite composition over inheritance whenever you can. That's it. Thank you so much for watching. Keep developing and to the next time.