Тёмный

Composite Pattern - Design Patterns (ep 14) 

Christopher Okhravi
Подписаться 155 тыс.
Просмотров 143 тыс.
50% 1

Video series on Design Patterns for Object Oriented Languages. This time we look at the Composite Pattern.
💙 BUY MY BOOK:
leanpub.com/the-object-orient...
► The playlist
• Design Patterns in Obj...
► Head First: Design Patterns
geni.us/nlbA6
► Design Patterns: Elements of Reusable Object-Oriented Software
geni.us/PsXmo
💪 Patreon Community
/ christopherokhravi
📚 Products I Recommend
geni.us/71ZXF

Опубликовано:

 

21 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 204   
@isaaczhu9223
@isaaczhu9223 6 лет назад
Thumb up for that board-eraser jump 16:03, hahaha
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
😊😊😊
@gerdkah6064
@gerdkah6064 5 лет назад
there ist a composition of 2 Christophers at 16:09 ^^
@sshanzel
@sshanzel 4 года назад
Chris: Jump at 16:03 Me: Subscribe (just kidding, ive been subs since ep 1)
@jriseup7201
@jriseup7201 6 лет назад
The best design patterns video tutorial series i've seen until now on youtube!
@pacoraby532
@pacoraby532 2 месяца назад
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.
@ChristopherOkhravi
@ChristopherOkhravi 2 месяца назад
😊😊😊
@prateeksharma9321
@prateeksharma9321 6 лет назад
I wish my university had teachers like you. Thank you!
@amiramohammed1568
@amiramohammed1568 Год назад
we are in 2023 and you are the best one out there teaching design patterns ! THANK YOU
@Koriyi
@Koriyi 3 года назад
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!
@user-ss2rj4wz5s
@user-ss2rj4wz5s 3 года назад
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!
@segafrompk
@segafrompk 4 года назад
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 RU-vid. 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!
@dp-bhatt
@dp-bhatt 6 лет назад
One of the best tutorials I have ever watched on Composite design pattern. Thank you very much.
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
Thanks :) I’m glad to hear :) Thanks for watching and for commenting.
@dannievasileva9069
@dannievasileva9069 Месяц назад
Thank you so much for this series, it has been immensely helpful. Please never stop teaching!
@yoruwamatahajimaru
@yoruwamatahajimaru Год назад
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.
@denispronin2417
@denispronin2417 5 лет назад
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
@nandukishore844
@nandukishore844 5 лет назад
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 .
@JitendraSarswat
@JitendraSarswat 6 лет назад
Yeah... I would love to see a discussion over recursion. Can you do that?
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
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 :)
@josipmareljic9092
@josipmareljic9092 5 лет назад
@@ChristopherOkhravi What ever approach you prefer, it doesn't matter, just do it. U R great
@prashantsomvanshi574
@prashantsomvanshi574 4 года назад
@@ChristopherOkhravi algorithm series please
@arthurfedotiew3609
@arthurfedotiew3609 2 года назад
“Removing this stuff” at 16:10 is the only thing you are better at than being the best OOP patterns teacher on RU-vid! For real, that was fookin epic!
@shankar7435
@shankar7435 5 месяцев назад
You mean is he not good at explaining patterns.
@shraddheshbhandari8740
@shraddheshbhandari8740 6 лет назад
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.
@EuanFR
@EuanFR 6 лет назад
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 :) ).
@ianauandrei
@ianauandrei 4 года назад
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.
@lucad4472
@lucad4472 4 года назад
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.
@henriquedesouza412
@henriquedesouza412 3 года назад
Thank u SO MUCH ! with 15 minutes of this content I could understand the composite design patter Greatings from Brazil !
@Messier_-82
@Messier_-82 6 лет назад
Great explanation as always! And yes, i'd like to see a video from you about recursion :)
@machi992
@machi992 3 года назад
I must say this channel is my discovery of the week.
@swellbot5738
@swellbot5738 6 лет назад
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.
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
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 :)
@swellbot5738
@swellbot5738 6 лет назад
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
@raghuhuchchannavar6184
@raghuhuchchannavar6184 2 года назад
The best design patterns video tutorial series i have seen until now . Superb
@josephtuk3834
@josephtuk3834 3 года назад
You have a clear voice, you explained well. You're good. Thank you.
@Defiguss
@Defiguss Год назад
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.
@salsaSamuel
@salsaSamuel 6 лет назад
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!
@ashishgarwal4103
@ashishgarwal4103 2 года назад
Super thumbs up, Christopher. You explained in a very simplified way.
@baja_taco3564
@baja_taco3564 Год назад
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!
@ta-cvig
@ta-cvig 3 года назад
Thanks for this series man. I learned a lot just from 2 videos thus far.
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
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 :/
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
It was quickly remonetized after a surprisingly quick manual review (thank you RU-vid). 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 :) :) :)
@JohnReloaded
@JohnReloaded 6 лет назад
Many others are experiencing the same issue for no reason, probably the algorithm still needs to "learn"
@BrutusPalmeira
@BrutusPalmeira 5 лет назад
Because you satisfied some NoAdvertise Pattern. If some ad shows advertising some other book, it is a fallacy ad principle.
@georgebadza
@georgebadza Год назад
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.
@elisedappollone8643
@elisedappollone8643 3 года назад
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?
@hanscesa5678
@hanscesa5678 2 года назад
Hi, have you got your answer already? Mind if you share it? I'm currently looking for it too
@Tall-Cool-Drink
@Tall-Cool-Drink 6 лет назад
Christopher, you have a way of making everything interesting.......lol....so discuss away, I'll be watching and listening.
@delulu6969
@delulu6969 2 года назад
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
@kartikmangal3218
@kartikmangal3218 2 года назад
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
@cyantulip
@cyantulip 6 лет назад
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! :-)
@JohnReloaded
@JohnReloaded 6 лет назад
Yes, a video about recursion, in particular about backtracking, would be great!
@anydobre1796
@anydobre1796 3 года назад
Absolutely. I would love to have recursion explained by Mr Christopher. Did he post anything like that, does anyone know?
@suyashpatel2652
@suyashpatel2652 5 лет назад
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?
@shinemperor8950
@shinemperor8950 5 лет назад
Loving this series. Thank you for this. I during the video you mention something about refactoring, branching logic and polymorphism. Was this video already made? (I haven't gone through all your content yet) Because I find the idea of replacing branching logic with polymorphism absolutely fascinating.
@sia-yx3wd
@sia-yx3wd 10 месяцев назад
You're so good at explaining!!! Thank you so much for these videos they're very helpful!!!!!!
@ShyamSharma-pg1zu
@ShyamSharma-pg1zu 3 года назад
Awesome . Listening you is like doing meditation . Its not easy to get out of focus
@vinokanthvelu2660
@vinokanthvelu2660 5 лет назад
@Christopher Okhravi Please do the algorithm series if you have time. Will be very useful :)
@martijn2973
@martijn2973 Год назад
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.
@anonymousmask4224
@anonymousmask4224 2 года назад
It's 2021 and still best explanation on the internet.
@codingwithgraceandtruth2456
@codingwithgraceandtruth2456 2 года назад
really enjoying your hard work. Thanks a lot!!!
@radiagulzan
@radiagulzan 4 года назад
You're an amazing teacher!
@VoyagerJourneys
@VoyagerJourneys 2 года назад
Hey man. I like your videos. I watch your video after I read one chapter of book. It is so helful for me.
@felixjost8206
@felixjost8206 2 года назад
The best explanations!
@leszektarnawski9460
@leszektarnawski9460 6 лет назад
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.
@moathnaji8505
@moathnaji8505 5 лет назад
thanks for the big effort its really clear, but i need to ask where the TodoList come from ?
@finestHQ
@finestHQ Год назад
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?
@DhrumilShahDOTin
@DhrumilShahDOTin 4 года назад
he specified so many times about books ... finally, I bought it on kindle ...
@ChristopherOkhravi
@ChristopherOkhravi 4 года назад
😊😊😊
@ribaker822
@ribaker822 5 лет назад
Hey Christopher, thanks again for this video. On your point on Interface Segregation Principle, while I agree with you, I thought that Leaf was not a client of Component, but actually is a component. Or maybe it's me not fully understanding the ISP?
@hfontanez98
@hfontanez98 5 лет назад
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.
@AshokKumar-uf5nj
@AshokKumar-uf5nj 4 года назад
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 ?
@mattgraves3709
@mattgraves3709 4 года назад
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...
@deathangel908
@deathangel908 6 лет назад
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.
@joannalai7147
@joannalai7147 2 года назад
Please cover the Visitor and Builder pattern if you plan to continue this series 🙏🏼
@Messier_-82
@Messier_-82 6 лет назад
I have a question: how do you create similar to existing (modified) immutable tree? I'd massively appreciate your answer)
@BrunoOlivera22
@BrunoOlivera22 3 года назад
my man!! great vids n explaining, much appreciated!!
@nesreenmosimi9925
@nesreenmosimi9925 6 лет назад
very useful and clear , thank you alot :)
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
Thank you. And thanks for watching 🙂🙂
@linux_lectures226
@linux_lectures226 Год назад
had to watch 3 times now i understand thanks man
@samanehmonemirad3723
@samanehmonemirad3723 3 года назад
may I ask you for preparing a new section for "Chain of Responsibility Design Pattern"?
@jvsnyc
@jvsnyc 2 года назад
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.
@feosys7695
@feosys7695 5 лет назад
man, its awesome channel, thank u
@ArtcodEAscetik
@ArtcodEAscetik 2 года назад
I've made some PHP HTMLElement with this D.P.. Works fine !
@MrEnsiferum77
@MrEnsiferum77 5 лет назад
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.
@piotrjaga6929
@piotrjaga6929 Год назад
that is awesome! thank you
@rajsoni7085
@rajsoni7085 11 месяцев назад
thanks for making this video .
@shayaxelrod7691
@shayaxelrod7691 3 года назад
"So what do we need to do, to do a todo list?" 🤯
@alecc8231
@alecc8231 4 года назад
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!
@prolamaamvs6952
@prolamaamvs6952 Год назад
deam this dude is going crazy :D love it
@_frank78
@_frank78 5 лет назад
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
@_frank78
@_frank78 5 лет назад
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 **".
@uniumuniu1176
@uniumuniu1176 5 лет назад
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.
@pedromedeiros6907
@pedromedeiros6907 Год назад
wonderful class
@maximkuzminsky
@maximkuzminsky 6 лет назад
hi Why can't we just omit Leaf class from the picture? Couldn't we simply use Project with empty todos instead?
@shanmukhchandrayama8508
@shanmukhchandrayama8508 3 года назад
we need a base condition right ,so for that we are using leaf class
@danielkapitanov1816
@danielkapitanov1816 6 лет назад
you're a life saver
@facundorodriguez92
@facundorodriguez92 6 лет назад
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!
@facundorodriguez92
@facundorodriguez92 6 лет назад
Sorry I should have done a search before suggesting. For those interested here speaks of similar concepts: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-zatcvoNqSaI.html
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
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 🙂
@MRarvai
@MRarvai 5 лет назад
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 ;)
@MRarvai
@MRarvai 5 лет назад
oh shoot, didn't see the correction because of the 2X speed, my bad :D :D
@TubeOutside
@TubeOutside 5 лет назад
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".
@sthoyyeti
@sthoyyeti 5 лет назад
LinkedList is having remove method. Thinking what's wrong with it? May be i didn't get your point.
@burakkalafat763
@burakkalafat763 Год назад
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
@bsuperbrain
@bsuperbrain 6 лет назад
Magic jump what removes stuff from the board. Haha! Anyway, nice to see this new one, long ago waited.
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
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 :)
@princekm5902
@princekm5902 4 года назад
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?
@nickbarton3191
@nickbarton3191 5 лет назад
Another excellent topic would be dependency injection. Trying to persuade my colleagues about the case for this because of the testability of units.
@lucadavidian5441
@lucadavidian5441 5 лет назад
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?
@BangsarRia
@BangsarRia Месяц назад
No. Traverse via a slightly different recursive algorithm. Or iterator.
@Lloysy
@Lloysy 6 лет назад
i'm pretty new to design patterns, but i think that the power of composite pattern is in its... mutability, which is needed to build a hierarchy. maybe i'm lacking of imagination but without add method, whiout changing the object you already have you can't really build a hierarchy... or i am wrong?
@MailsonWei
@MailsonWei 4 года назад
Can composite pattern use to for crafting feature?
@nawakoff2581
@nawakoff2581 2 года назад
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
@nawakoff2581
@nawakoff2581 2 года назад
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
@codenamesubho
@codenamesubho 5 лет назад
@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?
@codenamesubho
@codenamesubho 5 лет назад
oh there is another video for that :)
@nijuyonkadesu
@nijuyonkadesu 3 месяца назад
the pattern itself is so sophisticated, and now that I think about how to initialize this... ahhhh breaks my poor head
@ChristopherOkhravi
@ChristopherOkhravi 3 месяца назад
You got this! Hang in there! 💪
@khoinguyen-ft2ys
@khoinguyen-ft2ys 3 года назад
Thanks!
@NAVEENMV7
@NAVEENMV7 2 года назад
Why do we need a separate leaf todo. Can’t a leaf todo be replaced with a project todo with an empty todo list?
@tarike9808
@tarike9808 2 года назад
God bless you man
@danteeep
@danteeep 5 лет назад
thx this was great
@StevenLightning
@StevenLightning 3 года назад
I keep wondering, is “gang of four” a common term for four person authorship?
@HarshKumar-zo9kz
@HarshKumar-zo9kz 2 года назад
Can you create the video on chain responsibility,visitor,mediator pattern?
@MrZnSstr
@MrZnSstr 2 года назад
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.
@jamalbutt7864
@jamalbutt7864 6 лет назад
Chris! You are going to heaven. I wish I could meet you, and thank you in person! Best wishes from Pakistan!
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
Thank you for the blessing 😀 And thanks for watching :)
@BangsarRia
@BangsarRia Месяц назад
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.
Далее
Decorator Pattern - Design Patterns (ep 3)
54:35
Просмотров 477 тыс.
СДЕЛАЛА БРЕКЕТЫ ДОМА
01:01
Просмотров 1,3 млн
Adapter Pattern - Design Patterns (ep 8)
26:36
Просмотров 240 тыс.
Command Pattern - Design Patterns (ep 7)
39:12
Просмотров 266 тыс.
How principled coders outperform the competition
11:11
Why Use Design Patterns When Python Has Functions?
23:23
Facade Pattern - Design Patterns (ep 9)
16:19
Просмотров 179 тыс.
Only Use Inheritance If You Want Both of These
9:10
Просмотров 14 тыс.