 This video was brought to you by my patrons. Thank you so much for your support Hello there So I was studying some object-oriented design and I faced some techniques and some Terminologies that I'd like to share with you, but not as a tutorial I just want to raise the discussion about using this object-oriented design Terminologies and techniques in Godot engine. So let's start by talking about aggregation a very short description of aggregation is that it is a subset of Association so it implies that one object of one class owns an object of another class But here in aggregation we have a subtle difference because it is a specific subset of Association and it implies a relationship where the child the object that one class owns can exist Independently from the parent class. So let's try to understand this better using Godot engine Here in Godot one of the clearest examples that I can think about is the relationship between nodes and resources So if we go here in the help classes, we can see that we have note that inherits from object And we also have resource that inherits from reference some nodes most of the nodes use Resources in order to perform its behavior. So for instance, let's add a sprite here a Sprite can use a texture, right? So let's go here We have the Godot icon here and you can see that Godot icon is a texture here is a stream texture So help classes stream texture and it inherits from texture which inherits from resource If we drag and drop this resource here Now we have a sprite that aggregates a texture that aggregates a stream texture So this is the clearest examples that I can think about Another one is let's say a animation player. So if we create a new animation here Let's just say spin and if we save it to the disk Here we have the spin animation and if you go here in help classes Animation we'll see that an animation is also a resource and that the animation player is a node So the animation player uses it aggregates an animation So this list of animations that we have here is an aggregation of Animations in the animation player. So the animation player has a relationship of Aggregation with many animations and the reason why I think that this is a aggregation relationship So the sprite to aggregate a texture and the animation player aggregates some animations is that in aggregation? The child is independent from the parent. So they don't have a hard ownership between each other They don't have a hard ownership relation between each other. So let's see if we can try to prove that I will create a node here and I will add a script. So I will name this just test and Let's drag and drop the sprite as a child and what we'll do here is that I will create a var texture and On the ready function on the ready callback, I will say that the texture will be the sprite Dot texture and then I will kill free the sprite kill Free and here in the process callback We will try to access these textures. So let's try to print the texture here And the reason why I'm doing this is because in aggregation the parent and the child doesn't have a hard Ownership relation. So we can delete the parent which in this case is the sprite And we'll still have access to the child in this case the texture if everything goes well We'll have the texture printed here. So test it and here we have it So we have access to the texture even though the sprite is not available anymore. It was freaked from memory the next example and This one is not on me because I see a lot of people talking about this in the forums in the Scourge server the Facebook group is that the scene tree the way we arrange nodes in the scene tree It's also an aggregation relation. So if we add let's say a sprite and we add a Animation player here. We have a sprite that aggregates an animation player And if we save this I will save this just over this Okay, alright, and if we play this we have a sin tree. I will go to the remote sin tree here We have a sin tree, which is also a node that aggregates a view part Which is this root node so you can see that it is a view part here that aggregates a sprite That aggregates an animation player. Okay, but here's the thing I was searching in the web for how does aggregation work and I find out I will put this link to the source in the description so you can also have access to it But I will quote what they say in the screen right now It's important to note that the aggregation link doesn't state in any way that class a owns class B nor that there is a parent-child relationship But if we go here in the help classes node, we'll see that node Has a parameter a member property called owner very often This is just the root so in this case the case of animation player It will be the sprite but very often it can be the parent node of this node as well And we feel go down a little bit We have the add child which implies a child relationship and we also have get parent down here so we also have a parent-child relationship and I don't know if this is actually a Aggregation relationship that we have here in the sin tree So I would like to hear from you and another thing that I think that proves that this is not a Aggregation per se is that when we will see in the composition approach that when we use Composition it implies that the child's dependent on the parent So let's say if we free the parent we will also free the child But here in Godot here in the sin tree if we free the sprite for instance We will also free the animation player. So this will configure a composition not an aggregation So to prove that let's create another scene here I'll add a node drag this as its child and create another script here So I will call this test 2. Okay, and I will save this scene as test 2 as well And I was make basically the same thing. We'll have a var a On the beginning and a will be the animation player and then we'll free the sprite q Free and in the process callback will try to have access to this a node here So if they are indeed an aggregation So if the child doesn't depend on the state of the parent, we will have access to the animation player So let's print a here if they have a hard relationship between each other If they have a hard ownership between each other, we will not have access to the animation player anymore So I'll try to test this and We have here a deleted object So we don't have access to the animation player anymore And I think that this this is kind of strange because I heard from very professional people that the Sin tree makes use of an aggregation approach. So I don't know if this configurates or not I'll be very happy to hear from you what actually happens in the sin tree here But for this video, this is it if you like this kind of discussion If you like to talk about design patterns architectures engineering leave a thumbs up So I know that you want more of this content Don't forget to subscribe as well so that you know that I am producing this kind of content By the way, let's welcome adventures my newest patreon. Thank you so much for joining us and for this video That's it. I hope you enjoy it. Thank you for watching keep developing and to the next time