Тёмный

Difference Between Composite and Decorator Pattern - Design Patterns (ep 15) 

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

Video series on Design Patterns for Object Oriented Languages. This time we discuss the differences and similarities between Composite Pattern and Decorator 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
► Composite Pattern
• Composite Pattern - De...
► Decorator Pattern
• Decorator Pattern - De...
► SOLID Design Principles
• SOLID Design Principles
💪 Patreon Community
/ christopherokhravi
📚 Products I Recommend
geni.us/71ZXF

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

 

22 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 39   
@hfontanez98
@hfontanez98 5 лет назад
A list is still considered a hierarchical structure. It has a head (root), a tail (leaf), and potentially stuff in the middle. As you clearly stated, composite pattern is all about establishing the structure WITHOUT changing the underlying behavior of the component of the structure. Decorator is not about structure, but about changing (augmenting) the behavior of the component. Your example of decorator gave me an idea. In Rich Text Editors, text can be "decorated" with different styles like bolded, italicized, and underlined. It can also be decorated with color. It can also be decorated with font families. These decorations can be used in conjunction with each other. This sort of thing cannot (should not) be done using Composite Pattern. In the same context, Composite Pattern can be used to establish structures such as toolbars, menu bars, and even the document device context. This is important because (for instance) when you resize your Word Processor window, you will want to resize all of the children elements that belong to it (in order to keep the aspect ratio, for instance). This sort of functionality cannot (should not) be done with a Decorator Pattern. I think the confusion can be attributed in part (at least for me) to the fact that Decorator Pattern is categorized as a STRUCTURAL design pattern rather than BEHAVIORAL. I think this is a mistake because clearly the intent of the pattern is to add additional responsibilities (behaviors) to objects.
@lme918
@lme918 3 года назад
that was a good example! thanks.
@Levendo
@Levendo 4 года назад
I didnt even realize the similarity between the two patterns before watching this video. Thanks man!
@dp-bhatt
@dp-bhatt 6 лет назад
First time I understood the difference between Decorator and Composite design pattern super clearly. :) Thank you so much.
@anasfcb
@anasfcb 6 лет назад
Hey Christopher, Thanks a lot for "this kind" of videos, it allows us to complete and verify our understanding of the related specialized design pattern video. As you've mentionned (between the lines) it's only when you compare some similar design patterns that you start realizing that it's all about nuances. Please keep explaining the nuances in similar DP, it's just VERY helpful, and sincerely good luck in your PhD :)
@Jewelrumble
@Jewelrumble 5 лет назад
I've often found decorator very useful in game development. Works great with temporary boosts, score and timer multipliers, upgrades. Your videos are excellent
@michor10
@michor10 5 лет назад
Excellent video, as always, Christopher. I'm really enjoying this series. It's to just sit back watch you take these patterns apart. Cheers!
@naturalsmen1
@naturalsmen1 2 года назад
I like the way you explain the differences between the two patterns using references pointing upwards or downwards. Great work!
@josephfernando4867
@josephfernando4867 6 лет назад
Any particular reason for discussing differences ...are't they for completely different needs..composite for structure and decorator for adding functionality...Could you give similarities..that would be interesting.
@codingdave
@codingdave 2 года назад
If I just could like the complete video series more than once... Excellent content Christopher! 👍👍👍👍👍👍👍👍👍👍👍👍👍👍
@Ritesh91188
@Ritesh91188 6 лет назад
Chris, you are doing great work...Keep it up!! One request from my end.....Please make videos on system design(architecture with design patterns for parking lot, whatsapp, or any system) so it will be really helpful..............
@ChristopherOkhravi
@ChristopherOkhravi 6 лет назад
Thank you for watching and for your suggestion! Do you mean that you want more context? Like examples that are not just hypothetical but within a bigger context? Thank you again.
@andriikukuruza6844
@andriikukuruza6844 3 года назад
Wow, it blew my mind!
@TomKazanskyPolakow
@TomKazanskyPolakow 5 лет назад
I find your reasoning very interesting.
@RaviYadav-jb3nf
@RaviYadav-jb3nf 3 года назад
As I understood from the example, in composite all nodes will have same logic based on input from child-nodes. Whereas, in decorator each decorator-node may apply different logic on output from child decorator/component. Is above correct?
@henryjoe7853
@henryjoe7853 6 лет назад
Great video! could you do more of these nuances? There is even a similarity between composite and proxy. Also, there is some nuances between Adaptor and decorator e.t.c perhaps more of higher level nuances like presented in this video will help us more. Great work Christopher. I am now a fan :D
@utubeuser764
@utubeuser764 5 лет назад
great explanation
@B-Billy
@B-Billy 6 лет назад
Hey Cris... Thanks for great work, however could you please create video on "Flyweight"
@vaneet0
@vaneet0 4 года назад
Really Awesome
@robertczaja7151
@robertczaja7151 6 лет назад
Your Design Pattern series is really helpful! Despite I have a GoF book, when I want to check new pattern I watch your video first. Do you plan to cover patterns not presented in GoF book?
@VinodKumar-pf1un
@VinodKumar-pf1un 11 месяцев назад
Hi, thanks for sharing your thoughts :) Just one correction @1:26 "at runtime alter the behavior of some particular thing" aligns more closely with the Strategy pattern rather than the Decorator pattern. Decorator pattern is about extending or enhancing the behavior of individual objects in a flexible way without modifying/altering their original base classes.
@moawyahabdulrahman8782
@moawyahabdulrahman8782 Год назад
I like to think of decorator pattern as just adding (multiple) small functionality(ies) to the core logic of my object. But in composite pattern I think of it as "composing" multiple distinct functionality where each functionality has it's on identity. the composite object should not add functionality, It should compose the functionality of other objects in some what. (maybe apply all the changes once, maybe apply them in order or what ever). unlike decorators which have 1 and only 1 additional job to add.
@michaelyahyaev6747
@michaelyahyaev6747 2 года назад
I really like your videos 🔥🔥🔥
@Apiday
@Apiday 6 лет назад
Tu gères poto!
@angelrodriguez2259
@angelrodriguez2259 5 лет назад
Hi! Again, another great video. Could we say that another difference between patterns is that in Composite patterns the objective is that nodes have homogeneus functionalities while with the decorator we search for heterogeneus functionalities? Thanks a lot
@sthoyyeti
@sthoyyeti 5 лет назад
Good Example I can think of for Composite pattern: perform totalEmployees operation on LDAP tree from different levels say Org level, Business unit level, Section, Dept, Group, leaf returning zero.
@gigajoules6636
@gigajoules6636 5 лет назад
I guess you could use a decorator tree for some kind of layered damage system in a game? first branches could be body parts and then each split layer could be a different type of armour and then the branches from that are over-armour / buffs? Might be a bit explodey but hey.
@boblim623
@boblim623 4 месяца назад
相同的是,装饰器与组合模式都继承并聚合抽象类(接口),但区别是,装饰器是抽象类,而组合composite是具象类 The same thing is that both the decorator and composition patterns inherit and aggregate abstract classes (interfaces), but the difference is that the decorator is an abstract class, while the composite is a concrete class.
@boblim623
@boblim623 4 месяца назад
装饰器是一对一,而组合模式一般都是一对多The decorator is one -to -one, and the combination mode is generally one to many
@obi-center
@obi-center 5 лет назад
Thanks, bro ! You have a beer, when we meet :) Regards, Aleksandar
@fotios4902
@fotios4902 6 лет назад
What about the difference between the actual nodes of the two Patterns? i.e. in Decorator every node behaves differently. That's something you explicitly noted in the Decorator video bringing the example of Inputstream, Bufferstream etc. While in the Composite they all behave the same. Right? BTW thanks for the great videos!
@SelimAjimi
@SelimAjimi 6 лет назад
First and please continue sharing those videos ...
@bessermt
@bessermt 6 лет назад
GoF shows 1 Decorator in the diagram. See the last page of the book for the Class Diagram Notation. Arrow with no dot = one.
@kaustuvchatterjee4117
@kaustuvchatterjee4117 2 года назад
The basic definitions are the differences as you reiterated...Can following be the takeaway from this video?... Decorator is for applying multiple algorithm on single component... And Composite for applying single algorithm on multiple components(And subcomponents!!)... what do you say?
@iham1313
@iham1313 4 года назад
i love your vids - even they are a little aged (but who cares as it is about patterns, that are there for a long time) - but this time i can't follow Component is an interface -> IComponent that has two concrete implementations: Leaf and Composite - while Leaf has no further children the Composite does. otherwise the decorator pattern the Component is an interface too -> IComponent that has a concrete implementation: ConcreteComponent and an abstract class Decorator that has multiple ConcreteDecorators i sense difference here - beyond intend ;)
@sweetteddy390
@sweetteddy390 2 года назад
Decorator that decorates the decorator that decorates the decorator that decorates the component 😀
@PoulJulle-wb9iu
@PoulJulle-wb9iu 4 года назад
if decorator must have a comp, its a composition not aggregation
@eskindirabebegeda713
@eskindirabebegeda713 5 лет назад
Highly decorated lecture. let the viewer go and see the specific patterns , you could have done an on point session with
Далее
Iterator Pattern - Design Patterns (ep 16)
1:37:25
Просмотров 93 тыс.
Command Pattern - Design Patterns (ep 7)
39:12
Просмотров 266 тыс.
Decorator Pattern - Design Patterns (ep 3)
54:35
Просмотров 477 тыс.
Depend on Abstractions not Concretions (Framework)
11:56
Adapter Pattern - Design Patterns (ep 8)
26:36
Просмотров 240 тыс.
5 Design Patterns Every Engineer Should Know
11:51
Просмотров 935 тыс.
State Pattern - Design Patterns (ep 17)
1:20:30
Просмотров 149 тыс.
Template Method Pattern - Design Patterns (ep 13)
50:42
10 Design Patterns Explained in 10 Minutes
11:04
Просмотров 2,2 млн