I love how he confuses himself with all the open and close tags; man, that was pure gold. It just goes to show it happens to the best of us. This is the best pedagogical series on design patterns, hands down, and it's kind of funny on top of it. Thank you, Christopher.
Hi Christopher, I'm Italian, I'm studying Computer science at university. I'd like to thank you for this amazing playlist (GoF strategy patterns). I successfully passed the "Software engineering subject" with 30/30. Whiteout your video I would have never been able to do this. THANK YOU SO MUCH. I hope you will read this! I wish you the best. Sorry for any English mistakes.
I could have watched a movie or a series for 1 hour 11 minutes; however, i choose composite pattern! Kind of proud of it and happy to see people in the comments who cares about the code they write and appreciate a good design
This video still applicable in 2024. Amazing , it provides a solid exploration of the Composite Pattern, highlighting its usefulness in hierarchical structures and recursive operations. The emphasis on simplifying code through polymorphism and recursion is awesome. The discussion on immutability adds an important perspective, as it aligns well with modern C# practices.
This tutorial series is great! Right now I am watching all of them to study for my masters CS degree and I love your way of explaining things in a simple but entertaining way. Just wanted to say it is the best tutorial series on this topic i have found. Thank you so much!
Hey Chris! Love your videos and I'm learning so much from you! Thank you for making these, I really appreciate it! I'm sad that you are not uploading anymore, but that's life, I know it's hard to make a living on UA-cam. Hope you would make some CS course on udemy or a similar platform, you are a great teacher and you are great at making others pay attention even during these long videos. Cheers!
I was asked during an interview to design code that compute the price of boxes containing items. Assuming that each item inside the box has a price, and that the box itself has a price. I responded with a recursive code, including a "if" statement. When the interviewer asked about the composite pattern, which would have been another way of doing it, I didn't know... I somehow had the job. But now, I could talk about composite pattern (thanks :) ).
Holy shit, I've never had someone explain abstract concepts so clearly. Every single time I was thinking "but if he says this, how does this scenario work?", and like 3 seconds later, he would further explain exactly what I was doubting.
PING. All the explanations you are saying make a lot of sense and they really do make us (at least in my case) understand better and question our knowledge as WHY we do a certain thing. You are a good educator.
at around 27:00 min in the video you have mentioned "interface segregation principle" and you said leaves should not be forced to have add() and/remove() methods but what I think is leaves are not permanently leaves in this scenario .We can see leaves as children or teenagers who might become parents at some point of their life-cycle .
Hi! I am a newbie, I have been watching these videos in the playlist order, starting with the first one. In the beginning, I barely understood the abstract part and had to look up examples of patterns in the language I am studying to at least barely understand how they work. In this video, I finally understood the abstract pattern just from your explanation (and it took only a week and a half). Thank you.
This video got demonetized :( Anyone have an idea of why the algorithm flagged the video? Maybe the "correction boxes" that I put over my face when I said the wrong word looked like censoring bad language? I requested a manual review but have to wait for it :/
It was quickly remonetized after a surprisingly quick manual review (thank you UA-cam). Unfortunately I don't know why it originally was demonetized and I guess we won't get to know since (unless I remember incorrectly) the algorithm is neural network based :D But I would really guess it was the text-over mouth-boxes. That "pattern" ought to be common in videos with heavy use of foul language :) Makes sense right? Ps. thank you very much for the concern :) :) :)
You should go on the stage with such a proficient mimic and wonderful performances in front of the camera :) thank you for these series, I have got addicted to them
Great lessons, very easy-to-understand complex topics, even though the lessons are long. The type of aggregation arrows are necessary for UML diagrams sometimes, and they are not vague if you'll think about it. The aggregation arrows are of two types in UML, has one and has many, the one, used in this tutorial is - has many. So it means, that the particular component has many parent components.
Thanks for the ping :) :) I’m planning an algorithms series and this video will probably go into that series. Need to think a bit about how to approach it. Maybe I should just e.g. do a series where I compare non-recursive solutions to recursive solutions. Or something along those lines :) Thanks again for the ping and for watching :)
Had an exam 2 weeks ago, used all your videos for study and this one came up - was so gutted you hadn't made it sooner. Either way, here I am watching it because the quality of your videos are great. props. Keep on doing what you're doing.
I'm sorry to hear and terribly sorry I wasn't able to upload sooner :( It takes an outrageous amount of time to edit these videos :D Either way, I hope you do get a chance for a re-exam :) and I hope you nail it :D Thanks for watching and for the encouragement :)
Christopher Okhravi oh mate don't worry in the slightest. I just had to look elsewhere for this one, got it in the end, you just articulate and explain it so nicely you became a 'one stop shop'. I was hoping the strategy pattern would come up so I could wow them with your quote from sandi metz about inheritance haha :D Rock on, keep it up, look forward to your future videos
Great video. The ToDoList example nailed the principles of the pattern. Practical examples perfectly highlight the need and use of design patterns. The point you were trying to convey with the mutability discussion regarding whether a mutated object is the same object as before or a new one is actually a programmatic case of the famous paradox called Theseus's paradox.
That design patterns book is the required text for my Uni class, but I couldn't understand it. Thank you so much, these videos facilitate real learning!
You have a tremendous teaching gift bro I visit your videos still to this day. You can dice a complex concept into an understandable form for your listeners. I hope you are doing well bro!
Java Swing is built on this Design Pattern, where you have Container and Component. And really, that's how Composite Pattern should be designed. There is no need for a distinct "Leaf" class. A "Leaf" is simply a "Component" that has no sub-components. At any given point, a "Leaf" should accept new components and become a "Composite". Long story short, it is more effective to remove "Leaf" from the design and deal only with Containers and Components the way Java Swing have done it. Components containing zero sub-components are in essence leaves. However, you can transform this leaf into a composite simply by adding components to it. So, the best UML diagram for Composite Pattern is what is illustrated at 27:36 without the class "Leaf" in it.
Just to add, you don't necessarily need a heading tag inside li. Headings are for hierarchal structure of a sectioning element of the document like section, header, footer, etc (as opposed to of a flow content ie ul). You might need the first heading to make a new subsection for your list in relation to the section it's in, but not necessarily inside of them
Hey Chris, I really love while watching your videos coz you make it so interesting and easy to understand. I am very glad to have your DP series to learn from. I was wondering if you could please put a series on DSA as well coz I have been finding it difficult to make a proper decision in what way to start grasping them and what is the right resource for me but after watching your DP series I was wondering if you could please take out your precious time for a DSA series. Thanks and a lot of support
One could say that a Composite Pattern is useful when a node (object) could have two distinct roles (i.e. Parent or Child, Component or Container), depending if the point of reference or a given node is root or not.
Love these videos! I would be interested in seeing a further discussion about handling the add()/remove() scenarios with mutability vs. immutability. Did another video ever get made to go over how that would work?
I think at 24:00 b would be equal to 5 because the value of a is incremented after the operation ( Im only speaking for the few languages I know like C++ and C# , there might be some weird languages where this is not the case ) you'd have to use ++a ;)
Great video. There are some minor focus issues around 59:00 which had my eyes going googly while trying to read the updated code in the bottom right, but, great video.
I 100% agree on your statement regarding immutability, but in case of a tree structure, which could have many different nodes copying is quite expensive. Wondering what you would choose in such a scenario?
Great video. Only the thing is leaves do not have to implement Add and Remove methods if you don't define them at the interface, so this is not violating the interface segregation principle. We can need different methods on a composite node than leaves. It's very typical. I only can't entirely agree with that part. Other than that, it's a great explanation. Regards
First of all, I really must congratulate you for this series of videos. It is in absolute the best that I've ever seen on the design patterns. It's exhaustive and you succeed in explaining the design pattern having a good time. What I mostly appreciate, it is not the technical realization of the pattern itself, but the explanation of problem that is intended to be resolved, by adopting a specific pattern. (the "mind set" of the pattern). I have a question about the composite pattern: Is there really need of leaf class? I'm working on a project started by a very experienced software developer. He adopted the composite pattern but without using the leaf class; he simply uses just one class: the composite class. If a COMPOSITE instance has children, it is "considered" a "Complex-composite", if it has no children it is as a "Simple-composite" (a leaf in the original pattern, but in our case IT'S JUST A COMPOSITE CLASS INSTANCE WITH NO CHILDREN). When a component is added to a "Simple-composite", that one "becomes" automatically a "Complex-composite" (it was already an instance of composite class, but now it has children, and this is the only difference from its previous state). This involve the discussion about mutation (in our scenario, the mutation is a specific design request, and we cannot create a new tree, every time the data structure changes): In our scenario it is requested that the user can add to the system an "object of the real world" that it is, for instance a "car" and, at that specific time, the user has no information or doesn't want to insert them, about what a car is (at that point a "car" IS JUST A NAME, or a bunch of properties, and then it is a simple component, "a leaf" in the original pattern). In a second time, the user can or wants to specify what a car is: he specify that a car have four wheels (at this point a "wheel" IS just a name, or a bunch of properties, and then it is a simple component, a leaf, always in the original pattern), a shell (idem: a leaf) and an engine (again a leaf). In a third time, the user wants to define better what an engine is; so, it adds to the engine four cylinders (just names), a crankshaft (just a name), and so on... but by doing this the COMPOSITE CLASS INSTANCE "engine" becomes a "Complex-composite". Each time the user adds a new "real world object" to an existing simple component, the new "real world object" it's a leaf (or better a "Simple-composite") and its parent from a leaf, becomes a "Complex-composite". I repeat for clarity: I call them "Simple-composite" and "Complex-composite", but the class is just one: the Component. And finally, the question is: it is really needed to have two distinct objects: composite and leaf? (A father isn't just a PERSON with one or more children? and a child isn't just a PERSON without any children? (both of them are just a PERSON)) To me this approach (that is not type checking) has the big advantage to add semplicity to data structure and permits to manage all the objects in the same way. What do you think about it? Thank you very much
Sorry, i've made a mistake: "I repeat for clarity: I call them "Simple-composite" and "Complex-composite", but the class is just one: the ** COMPOSITE **".
In the video 'leaf' class exists to provide different implementation for 'getHtml()' method. Obviously you can use only one class but if implementation of some method differs depending on being 'simple' or 'complex' then you have to use conditional statement in that method (and that's what in some cases people tries to avoid by using good class structure). In your scenario (with mutation being part of your design) you don't really want to use 'leaf like class' because there is no way to assign further children to it. It sounds OK to me.
I absolutely have loved this series so far Chris. I'm in American I'm 40 years old and I don't think that I'm too far out there but I've never heard of Part whole hierarchies... well let me digress I have heard of it, in fact it was another composition design pattern video I was watching in which I heard that term....I just don't know what it means I've never had it to find for me...
26:50 I feel very confused now, `no client should be forced to depend on methods it does not use`, a client = `has a`, not `is a`. In your scenario, it breaks Linskov's Substitution principle, as a Component can't be replaced with a Leaf. Please correct me if I'm wrong.
So what's the difference between composite pattern and n-ary tree? For example implementation In Javascript, the Node hold array as reference to all childs down the tree.
doesn't matter much for this example, but when you talk about mutation you say @24:27 you say that b will be 6, but that's not true, you used the post decrement opperator, the value of a is returned before it is incremented, so b would actually be set to 5, and then a becomes 6.
In the book it was very confusing, this pattern it mixes my weakest skills in programming. Trees and recursion, I know conceptually what they are, but regarding trees I never used them for a solution and I can't visualize much their ideas and recursion I used it at some point with basic programs like fibonacci algorithm, but its not like I am experienced with it. I hope your video will make more sense. Edit: Oh shit, I went checking on trees again and I ended up watching the MIT classes.. quite a rabbithole and I am back.
regarding the discussion about where to put add/remove(), what if there's no separate classes for leaf vs composite. What if all you got is just "component" concrete class, so logically if it doesn't contain any other component, then it should be treated as leaf, otherwise composite, then there's no need to discuss where to put the add/remove method and yet still have a "composite pattern".
Hey Chris! Thank you so much for doing these videos. Your explanations are well thought-out and very comprehensive. I find them very helpful. I have a request for you. Could you please do a video about shared libraries, static vs dynamic linkage, implicit vs explicit loading, in a modern OS environment (i.e. how things work now, not how they used to work 20 years ago.) Oh, and I’d be interested in that recursion discussion too. Thanks again, and keep up the good work! :-)
Thanks for making such awesome videos. I have one doubt. Why you put the logic of wrapping "ToDo" text inside in "Project" class. Shouldn't it be responsibility of "ToDo::GetHTML()" method?
Hello Christopher, I would like to know if there is a possibility that you dedicate any video to the concept of TDD. I am beginning to immerse myself in that subject and I would like to know your opinion about it. Thank you very much. Saludos desde Argentina!
Nice! You were pretty quick to find it though :) :) Lemme know if you find anything specific in the videos that you would like me to explore further in future videos. Also, thank you very much for suggesting topics and thank you very much for following the channel 🙂
Great video and the whole series. And since I am here - isn't folders structure an example of composite pattern? It is a mutable tree and any node could be either a folder or a file (leaf) but we don't want to care about it when doing operations on them - add, delete, etc. I can't think of any other way of doing folders structure.
Chris, another wonderful example and explanation of the pattern! Though I think, the interface name should've been like "TodoItem" instead of "TodoList". Then simple leaf implementation will be SingleItem: TodoItem. and ProjectItem: TodoItem. Does it make sense? Name "ToDoList" as an interface is confusing because it's implying a list of items already. Thanks, Christopher!
I understand it is all about mutability, but wouldn't it be more flexible to create just one class and determine whether it a leaf or a composite based on whether it contains subitems or not at all? Of course, it would force us to use a conditional, but it seems to be more like a composition over inheritance
But yes, I guess it depends on the specific case, whether we need to wrap composites into new ones without altering the first ones, or we will know the entire structure and just use constructor, or we need to extend different nodes dynamically
Hi Christopher, I have seen your video about strategic pattern.In that you discuss about the rubber duck and IFlyBehaviour interface.Similarly Can't I make an interface "IAddBehaviour" for Component and define add() into it and create two more interfaces from IAddBehaviour.Let's say AddNotSupportedBehaviour and AddSupportedBehaviour for leaf and composite respectively.Doesn't that make sense?Shouldn't we be doing that?
Hi @Okhravi, Super likes the series. But I don't see the Builder and Chain of responsibility patterns covered in the playlist. Can you point me to these if you have covered ?
@christopher, I am confused. Doesn't decorator pattern code look the same? you add some functionality and pass the request to the successor decorator untill you reach the terminating decorator?
GoF intends that the Composite Pattern be used in cases that the Client does not have to distinguish between Nodes and Leaves. GoF p167, point 4 expressly addresses the issues of ISP and LSP: "trade-off between safety and transparency". GoF's use of "transparency" here makes me uncomfortable, because I don't think they mean that at all, and the word does not appear in the index, so we don't know what they mean by it. In this context I think they mean "uniformity", or even "abstraction". While we're talking about terminology, GOF was published before Java was revealed. So we see "operation" for "method" throughout. They might have gone with "function" instead of "method" anyway, as not all languages use "method" and "member" etc as terms.
What about different traversal orders of the tree structure? I see that the video uses preorder (I visit the root node, then the left subtree, then the right one, in the case of a binary tree). I understand how to implement inorder and postorder. These are all depth first traversals. What if I want to traverse the tree structure in level order (breadth first)? Does the recursive nature of the Composite pattern disallow that?
Thumb up for that board-eraser jump 16:03, hahaha
😊😊😊
there ist a composition of 2 Christophers at 16:09 ^^
Chris: Jump at 16:03
Me: Subscribe (just kidding, ive been subs since ep 1)
we are in 2023 and you are the best one out there teaching design patterns ! THANK YOU
I love how he confuses himself with all the open and close tags; man, that was pure gold. It just goes to show it happens to the best of us. This is the best pedagogical series on design patterns, hands down, and it's kind of funny on top of it. Thank you, Christopher.
😊😊😊
The best design patterns video tutorial series i've seen until now on youtube!
I wish my university had teachers like you.
Thank you!
One of the best tutorials I have ever watched on Composite design pattern. Thank you very much.
Thanks :) I’m glad to hear :) Thanks for watching and for commenting.
“Removing this stuff” at 16:10 is the only thing you are better at than being the best OOP patterns teacher on UA-cam! For real, that was fookin epic!
You mean is he not good at explaining patterns.
Hi Christopher, I'm Italian, I'm studying Computer science at university. I'd like to thank you for this amazing playlist (GoF strategy patterns). I successfully passed the "Software engineering subject" with 30/30. Whiteout your video I would have never been able to do this. THANK YOU SO MUCH. I hope you will read this! I wish you the best. Sorry for any English mistakes.
I could have watched a movie or a series for 1 hour 11 minutes; however, i choose composite pattern! Kind of proud of it and happy to see people in the comments who cares about the code they write and appreciate a good design
This video still applicable in 2024. Amazing , it provides a solid exploration of the Composite Pattern, highlighting its usefulness in hierarchical structures and recursive operations. The emphasis on simplifying code through polymorphism and recursion is awesome. The discussion on immutability adds an important perspective, as it aligns well with modern C# practices.
Thank you so much for this series, it has been immensely helpful. Please never stop teaching!
I must say this channel is my discovery of the week.
This tutorial series is great! Right now I am watching all of them to study for my masters CS degree and I love your way of explaining things in a simple but entertaining way. Just wanted to say it is the best tutorial series on this topic i have found. Thank you so much!
Thank u SO MUCH !
with 15 minutes of this content I could understand the composite design patter
Greatings from Brazil !
Hey Chris! Love your videos and I'm learning so much from you! Thank you for making these, I really appreciate it! I'm sad that you are not uploading anymore, but that's life, I know it's hard to make a living on UA-cam. Hope you would make some CS course on udemy or a similar platform, you are a great teacher and you are great at making others pay attention even during these long videos. Cheers!
I was asked during an interview to design code that compute the price of boxes containing items. Assuming that each item inside the box has a price, and that the box itself has a price.
I responded with a recursive code, including a "if" statement.
When the interviewer asked about the composite pattern, which would have been another way of doing it, I didn't know... I somehow had the job.
But now, I could talk about composite pattern (thanks :) ).
Holy shit, I've never had someone explain abstract concepts so clearly. Every single time I was thinking "but if he says this, how does this scenario work?", and like 3 seconds later, he would further explain exactly what I was doubting.
PING. All the explanations you are saying make a lot of sense and they really do make us (at least in my case) understand better and question our knowledge as WHY we do a certain thing. You are a good educator.
at around 27:00 min in the video you have mentioned "interface segregation principle" and you said leaves should not be forced to have add() and/remove() methods but what I think is leaves are not permanently leaves in this scenario .We can see leaves as children or teenagers who might become parents at some point of their life-cycle .
The best discussion about this pattern I'd found on youtube. That's what I was looking for after reading the book's chapter. Thank you!
Hi! I am a newbie, I have been watching these videos in the playlist order, starting with the first one. In the beginning, I barely understood the abstract part and had to look up examples of patterns in the language I am studying to at least barely understand how they work. In this video, I finally understood the abstract pattern just from your explanation (and it took only a week and a half). Thank you.
The best design patterns video tutorial series i have seen until now . Superb
This video got demonetized :( Anyone have an idea of why the algorithm flagged the video? Maybe the "correction boxes" that I put over my face when I said the wrong word looked like censoring bad language? I requested a manual review but have to wait for it :/
It was quickly remonetized after a surprisingly quick manual review (thank you UA-cam). Unfortunately I don't know why it originally was demonetized and I guess we won't get to know since (unless I remember incorrectly) the algorithm is neural network based :D But I would really guess it was the text-over mouth-boxes. That "pattern" ought to be common in videos with heavy use of foul language :) Makes sense right? Ps. thank you very much for the concern :) :) :)
Many others are experiencing the same issue for no reason, probably the algorithm still needs to "learn"
Because you satisfied some NoAdvertise Pattern. If some ad shows advertising some other book, it is a fallacy ad principle.
You should go on the stage with such a proficient mimic and wonderful performances in front of the camera :) thank you for these series, I have got addicted to them
Great lessons, very easy-to-understand complex topics, even though the lessons are long.
The type of aggregation arrows are necessary for UML diagrams sometimes, and they are not vague if you'll think about it.
The aggregation arrows are of two types in UML, has one and has many, the one, used in this tutorial is - has many.
So it means, that the particular component has many parent components.
You have a clear voice, you explained well. You're good. Thank you.
Yeah... I would love to see a discussion over recursion. Can you do that?
Thanks for the ping :) :) I’m planning an algorithms series and this video will probably go into that series. Need to think a bit about how to approach it. Maybe I should just e.g. do a series where I compare non-recursive solutions to recursive solutions. Or something along those lines :) Thanks again for the ping and for watching :)
@@ChristopherOkhravi What ever approach you prefer, it doesn't matter, just do it. U R great
@@ChristopherOkhravi algorithm series please
It's 2021 and still best explanation on the internet.
Had an exam 2 weeks ago, used all your videos for study and this one came up - was so gutted you hadn't made it sooner. Either way, here I am watching it because the quality of your videos are great. props. Keep on doing what you're doing.
I'm sorry to hear and terribly sorry I wasn't able to upload sooner :( It takes an outrageous amount of time to edit these videos :D Either way, I hope you do get a chance for a re-exam :) and I hope you nail it :D Thanks for watching and for the encouragement :)
Christopher Okhravi oh mate don't worry in the slightest. I just had to look elsewhere for this one, got it in the end, you just articulate and explain it so nicely you became a 'one stop shop'.
I was hoping the strategy pattern would come up so I could wow them with your quote from sandi metz about inheritance haha :D
Rock on, keep it up, look forward to your future videos
Christopher, you have a way of making everything interesting.......lol....so discuss away, I'll be watching and listening.
Awesome . Listening you is like doing meditation . Its not easy to get out of focus
Great video. The ToDoList example nailed the principles of the pattern. Practical examples perfectly highlight the need and use of design patterns.
The point you were trying to convey with the mutability discussion regarding whether a mutated object is the same object as before or a new one is actually a programmatic case of the famous paradox called Theseus's paradox.
Super thumbs up, Christopher. You explained in a very simplified way.
Thank you so much! You can't imagine how helpful these videos are. At least for me, this seems like the best way to explain design patterns.
he specified so many times about books ... finally, I bought it on kindle ...
😊😊😊
That design patterns book is the required text for my Uni class, but I couldn't understand it. Thank you so much, these videos facilitate real learning!
Yes, a video about recursion, in particular about backtracking, would be great!
Absolutely. I would love to have recursion explained by Mr Christopher. Did he post anything like that, does anyone know?
Hey man. I like your videos. I watch your video after I read one chapter of book. It is so helful for me.
You're so good at explaining!!! Thank you so much for these videos they're very helpful!!!!!!
You have a tremendous teaching gift bro I visit your videos still to this day. You can dice a complex concept into an understandable form for your listeners. I hope you are doing well bro!
Great explanation as always! And yes, i'd like to see a video from you about recursion :)
Java Swing is built on this Design Pattern, where you have Container and Component. And really, that's how Composite Pattern should be designed. There is no need for a distinct "Leaf" class. A "Leaf" is simply a "Component" that has no sub-components. At any given point, a "Leaf" should accept new components and become a "Composite". Long story short, it is more effective to remove "Leaf" from the design and deal only with Containers and Components the way Java Swing have done it. Components containing zero sub-components are in essence leaves. However, you can transform this leaf into a composite simply by adding components to it. So, the best UML diagram for Composite Pattern is what is illustrated at 27:36 without the class "Leaf" in it.
Thanks for this series man. I learned a lot just from 2 videos thus far.
I've made some PHP HTMLElement with this D.P.. Works fine !
had to watch 3 times now i understand thanks man
Just to add, you don't necessarily need a heading tag inside li. Headings are for hierarchal structure of a sectioning element of the document like section, header, footer, etc (as opposed to of a flow content ie ul). You might need the first heading to make a new subsection for your list in relation to the section it's in, but not necessarily inside of them
Hey Chris,
I really love while watching your videos coz you make it so interesting and easy to understand. I am very glad to have your DP series to learn from.
I was wondering if you could please put a series on DSA as well coz I have been finding it difficult to make a proper decision in what way to start grasping them and what is the right resource for me but after watching your DP series I was wondering if you could please take out your precious time for a DSA series.
Thanks and a lot of support
One could say that a Composite Pattern is useful when a node (object) could have two distinct roles (i.e. Parent or Child, Component or Container), depending if the point of reference or a given node is root or not.
very useful and clear , thank you alot :)
Thank you. And thanks for watching 🙂🙂
Love these videos! I would be interested in seeing a further discussion about handling the add()/remove() scenarios with mutability vs. immutability. Did another video ever get made to go over how that would work?
Hi, have you got your answer already? Mind if you share it? I'm currently looking for it too
"So what do we need to do, to do a todo list?" 🤯
the pattern itself is so sophisticated, and now that I think about how to initialize this...
ahhhh
breaks my poor head
You got this! Hang in there! 💪
@Christopher Okhravi Please do the algorithm series if you have time. Will be very useful :)
really enjoying your hard work. Thanks a lot!!!
I think at 24:00 b would be equal to 5 because the value of a is incremented after the operation ( Im only speaking for the few languages I know like C++ and C# , there might be some weird languages where this is not the case ) you'd have to use ++a ;)
oh shoot, didn't see the correction because of the 2X speed, my bad :D :D
The best explanations!
Great video. There are some minor focus issues around 59:00 which had my eyes going googly while trying to read the updated code in the bottom right, but, great video.
You're an amazing teacher!
hi
Why can't we just omit Leaf class from the picture? Couldn't we simply use Project with empty todos instead?
we need a base condition right ,so for that we are using leaf class
I 100% agree on your statement regarding immutability, but in case of a tree structure, which could have many different nodes copying is quite expensive. Wondering what you would choose in such a scenario?
my man!! great vids n explaining, much appreciated!!
Great video. Only the thing is leaves do not have to implement Add and Remove methods if you don't define them at the interface, so this is not violating the interface segregation principle. We can need different methods on a composite node than leaves. It's very typical. I only can't entirely agree with that part. Other than that, it's a great explanation. Regards
First of all, I really must congratulate you for this series of videos.
It is in absolute the best that I've ever seen on the design patterns.
It's exhaustive and you succeed in explaining the design pattern having a good time.
What I mostly appreciate, it is not the technical realization of the pattern itself,
but the explanation of problem that is intended to be resolved, by adopting a specific pattern.
(the "mind set" of the pattern).
I have a question about the composite pattern:
Is there really need of leaf class?
I'm working on a project started by a very experienced software developer. He adopted the composite pattern but without using the leaf class; he simply uses just one class: the composite class. If a COMPOSITE instance has children, it is "considered" a "Complex-composite", if it has no children it is as a "Simple-composite" (a leaf in the original pattern, but in our case IT'S JUST A COMPOSITE CLASS INSTANCE WITH NO CHILDREN).
When a component is added to a "Simple-composite", that one "becomes" automatically a "Complex-composite" (it was already an instance of composite class, but now it has children, and this is the only difference from its previous state).
This involve the discussion about mutation (in our scenario, the mutation is a specific design request, and we cannot create a new tree, every time the data structure changes):
In our scenario it is requested that the user can add to the system an "object of the real world" that it is, for instance a "car" and,
at that specific time, the user has no information or doesn't want to insert them, about what a car is (at that point a "car" IS JUST A NAME, or a bunch of properties, and then it is a simple component, "a leaf" in the original pattern).
In a second time, the user can or wants to specify what a car is: he specify that a car have four wheels (at this point a "wheel" IS just a name, or a bunch of properties, and then it is a simple component, a leaf, always in the original pattern), a shell (idem: a leaf) and an engine (again a leaf).
In a third time, the user wants to define better what an engine is; so, it adds to the engine four cylinders (just names), a crankshaft (just a name), and so on... but by doing this the COMPOSITE CLASS INSTANCE "engine" becomes a "Complex-composite".
Each time the user adds a new "real world object" to an existing simple component, the new "real world object" it's a leaf (or better a "Simple-composite") and its parent from a leaf, becomes a "Complex-composite".
I repeat for clarity: I call them "Simple-composite" and "Complex-composite", but the class is just one: the Component.
And finally, the question is: it is really needed to have two distinct objects: composite and leaf?
(A father isn't just a PERSON with one or more children? and a child isn't just a PERSON without any children? (both of them are just a PERSON))
To me this approach (that is not type checking) has the big advantage to add semplicity to data structure and permits to manage all the objects in the same way.
What do you think about it?
Thank you very much
Sorry, i've made a mistake: "I repeat for clarity: I call them "Simple-composite" and "Complex-composite", but the class is just one: the ** COMPOSITE **".
In the video 'leaf' class exists to provide different implementation for 'getHtml()' method. Obviously you can use only one class but if implementation of some method differs depending on being 'simple' or 'complex' then you have to use conditional statement in that method (and that's what in some cases people tries to avoid by using good class structure). In your scenario (with mutation being part of your design) you don't really want to use 'leaf like class' because there is no way to assign further children to it. It sounds OK to me.
I absolutely have loved this series so far Chris.
I'm in American I'm 40 years old and I don't think that I'm too far out there but I've never heard of Part whole hierarchies... well let me digress I have heard of it, in fact it was another composition design pattern video I was watching in which I heard that term....I just don't know what it means I've never had it to find for me...
26:50 I feel very confused now, `no client should be forced to depend on methods it does not use`, a client = `has a`, not `is a`. In your scenario, it breaks Linskov's Substitution principle, as a Component can't be replaced with a Leaf. Please correct me if I'm wrong.
deam this dude is going crazy :D love it
Please cover the Visitor and Builder pattern if you plan to continue this series 🙏🏼
may I ask you for preparing a new section for "Chain of Responsibility Design Pattern"?
So what's the difference between composite pattern and n-ary tree? For example implementation In Javascript, the Node hold array as reference to all childs down the tree.
Another excellent topic would be dependency injection. Trying to persuade my colleagues about the case for this because of the testability of units.
Magic jump what removes stuff from the board. Haha! Anyway, nice to see this new one, long ago waited.
Yeeeeah :) My editing skills are sub-par so it was tricky to figure out how to do it :D Thanks for watching and I hope the video was accommodating :)
doesn't matter much for this example, but when you talk about mutation you say @24:27 you say that b will be 6, but that's not true, you used the post decrement opperator, the value of a is returned before it is incremented, so b would actually be set to 5, and then a becomes 6.
In the book it was very confusing, this pattern it mixes my weakest skills in programming. Trees and recursion, I know conceptually what they are, but regarding trees I never used them for a solution and I can't visualize much their ideas and recursion I used it at some point with basic programs like fibonacci algorithm, but its not like I am experienced with it. I hope your video will make more sense.
Edit: Oh shit, I went checking on trees again and I ended up watching the MIT classes.. quite a rabbithole and I am back.
Yes please, hope you can explain recursion as good as you teach design patterns.
Thanks for the feedback :)
regarding the discussion about where to put add/remove(), what if there's no separate classes for leaf vs composite. What if all you got is just "component" concrete class, so logically if it doesn't contain any other component, then it should be treated as leaf, otherwise composite, then there's no need to discuss where to put the add/remove method and yet still have a "composite pattern".
you're a life saver
man, its awesome channel, thank u
Hey Chris! Thank you so much for doing these videos. Your explanations are well thought-out and very comprehensive. I find them very helpful.
I have a request for you. Could you please do a video about shared libraries, static vs dynamic linkage, implicit vs explicit loading, in a modern OS environment (i.e. how things work now, not how they used to work 20 years ago.)
Oh, and I’d be interested in that recursion discussion too.
Thanks again, and keep up the good work! :-)
Thanks for making such awesome videos. I have one doubt. Why you put the logic of wrapping "ToDo" text inside in "Project" class. Shouldn't it be responsibility of "ToDo::GetHTML()" method?
wonderful class
thanks for making this video .
Hello Christopher,
I would like to know if there is a possibility that you dedicate any video to the concept of TDD. I am beginning to immerse myself in that subject and I would like to know your opinion about it.
Thank you very much.
Saludos desde Argentina!
Sorry I should have done a search before suggesting. For those interested here speaks of similar concepts:
ua-cam.com/video/zatcvoNqSaI/v-deo.html
Nice! You were pretty quick to find it though :) :) Lemme know if you find anything specific in the videos that you would like me to explore further in future videos. Also, thank you very much for suggesting topics and thank you very much for following the channel 🙂
An hour video for one PATTERN? Yup I'm going to fail my exam.
Great video and the whole series. And since I am here - isn't folders structure an example of composite pattern? It is a mutable tree and any node could be either a folder or a file (leaf) but we don't want to care about it when doing operations on them - add, delete, etc. I can't think of any other way of doing folders structure.
lol.....I glad I'm not the only one confused by "part-whole"......I'm confused by many phrases like this throughout software coding methods.....
that is awesome! thank you
Chris, another wonderful example and explanation of the pattern!
Though I think, the interface name should've been like "TodoItem" instead of "TodoList". Then simple leaf implementation will be SingleItem: TodoItem. and ProjectItem: TodoItem.
Does it make sense? Name "ToDoList" as an interface is confusing because it's implying a list of items already.
Thanks, Christopher!
Can composite pattern use to for crafting feature?
God bless you man
I understand it is all about mutability, but wouldn't it be more flexible to create just one class and determine whether it a leaf or a composite based on whether it contains subitems or not at all? Of course, it would force us to use a conditional, but it seems to be more like a composition over inheritance
But yes, I guess it depends on the specific case, whether we need to wrap composites into new ones without altering the first ones, or we will know the entire structure and just use constructor, or we need to extend different nodes dynamically
Hi Christopher, I have seen your video about strategic pattern.In that you discuss about the rubber duck and IFlyBehaviour interface.Similarly Can't I make an interface "IAddBehaviour" for Component and define add() into it and create two more interfaces from IAddBehaviour.Let's say AddNotSupportedBehaviour and AddSupportedBehaviour for leaf and composite respectively.Doesn't that make sense?Shouldn't we be doing that?
Hi @Okhravi, Super likes the series. But I don't see the Builder and Chain of responsibility patterns covered in the playlist. Can you point me to these if you have covered ?
@christopher, I am confused. Doesn't decorator pattern code look the same? you add some functionality and pass the request to the successor decorator untill you reach the terminating decorator?
oh there is another video for that :)
Oh man, too detailed example, we understand it :D I had to rewind forward 15 mins xD Anyway, good job man! Keep up!
Why do we need a separate leaf todo. Can’t a leaf todo be replaced with a project todo with an empty todo list?
GoF intends that the Composite Pattern be used in cases that the Client does not have to distinguish between Nodes and Leaves.
GoF p167, point 4 expressly addresses the issues of ISP and LSP: "trade-off between safety and transparency".
GoF's use of "transparency" here makes me uncomfortable, because I don't think they mean that at all, and the word does not appear in the index, so we don't know what they mean by it. In this context I think they mean "uniformity", or even "abstraction".
While we're talking about terminology, GOF was published before Java was revealed. So we see "operation" for "method" throughout. They might have gone with "function" instead of "method" anyway, as not all languages use "method" and "member" etc as terms.
What about different traversal orders of the tree structure? I see that the video uses preorder (I visit the root node, then the left subtree, then the right one, in the case of a binary tree). I understand how to implement inorder and postorder. These are all depth first traversals. What if I want to traverse the tree structure in level order (breadth first)? Does the recursive nature of the Composite pattern disallow that?
No. Traverse via a slightly different recursive algorithm. Or iterator.
"I don't wanna talk about recursion if u r not familiar with recursion." 😆
16:07 Didn't see that coming
Great video 👍
Can u talk more about mutable