Decorator Design Pattern

  Рет қаралды 423,145

Derek Banas

Derek Banas

11 жыл бұрын

Get the Cheat Sheet: goo.gl/MzW0g
Best Design Patterns Book : goo.gl/W0wyie
Welcome to my Decorator Design Pattern Tutorial. The Decorator allows you to modify an object dynamically. You would use it when you want the capabilities of inheritance with subclasses, but you need to add functionality at run time.
It is more flexible than inheritance. The Decorator Design Pattern simplifies code because you add functionality using many simple classes. Also, rather than rewrite old code you can extend it with new code and that is always good.

Пікірлер: 567
@derekbanas
@derekbanas 5 жыл бұрын
Learn in One Videos for Every Programming Language Subscribe to Bookmark them: bit.ly/2FWQZTx C++ : kzfaq.info/get/bejne/iNuSYK2kz7PMh40.html Python : kzfaq.info/get/bejne/hJqdeN13qdDVpHU.html Java : kzfaq.info/get/bejne/pJOodNSUp6nbo2g.html PHP : kzfaq.info/get/bejne/bbp2Y5OZr6-baI0.html MySQL : kzfaq.info/get/bejne/r7aladSHmsjdpWg.html JavaScript : kzfaq.info/get/bejne/nNClbMyanb_Xd6c.html C# : kzfaq.info/get/bejne/os-jnNqGv7C8oYU.html HTML5 : kzfaq.info/get/bejne/oaqpfbFo1rephHU.html CSS3 : kzfaq.info/get/bejne/ebuoe8KjvLmtYZ8.html JQuery : kzfaq.info/get/bejne/eL2ImspzkrqVmoU.html TypeScript : kzfaq.info/get/bejne/Y7aCkruivJ-ueok.html ECMAScript : kzfaq.info/get/bejne/gMebosxhrJ7Qcps.html Swift : kzfaq.info/get/bejne/mrGRos2Av5PFqmw.html R : kzfaq.info/get/bejne/qZl2ot2Hy8qboWg.html Haskell : kzfaq.info/get/bejne/ZpiPe5Z9z9exomw.html Handlebars : kzfaq.info/get/bejne/aq6ldNF-m8iWlGw.html Bootstrap : kzfaq.info/get/bejne/ndd_eNKGt5u2eJs.html Rust : kzfaq.info/get/bejne/i5d1ecp0s7Kocmw.html Matlab : kzfaq.info/get/bejne/hLmDh86csLjFkn0.html Arduino : kzfaq.info/get/bejne/h7WPfc-rltfUdKs.html Crystal : kzfaq.info/get/bejne/et52g5CIz9fYo5c.html Emacs : kzfaq.info/get/bejne/f8eXldlqnJqrnIU.html Clojure : kzfaq.info/get/bejne/mc93rKucqdu0cXk.html Shell : kzfaq.info/get/bejne/nt2iodCC2tPYgKs.html Perl : kzfaq.info/get/bejne/jauXm6yJ2J6qZpc.html Perl6 : kzfaq.info/get/bejne/opaqg9qZzL24l4E.html Elixir : kzfaq.info/get/bejne/pqh-gsSnt9WyfGQ.html D : kzfaq.info/get/bejne/qN2Kebefy5_GdIk.html Fortran : kzfaq.info/get/bejne/lcViiMp3s7_Llmw.html LaTeX : kzfaq.info/get/bejne/jM6dnq-jtNCwo6s.html F# : kzfaq.info/get/bejne/mZ2Vgad7s52ZaIk.html Kotlin : kzfaq.info/get/bejne/fsWfesxp2tuooHU.html Erlang : kzfaq.info/get/bejne/f6uYqsZj1pfed2g.html Groovy : kzfaq.info/get/bejne/eJ9oncZpzcrZaZs.html Scala : kzfaq.info/get/bejne/euB2p5OK0MDTaIE.html Lua : kzfaq.info/get/bejne/n7ORltuLtrO0iKc.html Ruby : kzfaq.info/get/bejne/etCZbKR9qM3KoIE.html Go : kzfaq.info/get/bejne/eaxphpeCv9u6Y2Q.html Objective C : kzfaq.info/get/bejne/a8ujhNSLrrCcY5s.html Prolog : kzfaq.info/get/bejne/id-bq7qhq92xd6c.html LISP : kzfaq.info/get/bejne/r9ODpJeordjVqYk.html Express : kzfaq.info/get/bejne/rqpzfsZ_p6zXpX0.html Jade : kzfaq.info/get/bejne/optxi8aJpraYomw.html Sass : kzfaq.info/get/bejne/reBjnqidscipeHk.html
@yuxiwan8917
@yuxiwan8917 6 жыл бұрын
Move the "adding dough" to plain pizza class then the video is perfect!
@IronMeDen1
@IronMeDen1 2 жыл бұрын
10 years later and this video is still one of the easiest to follow and best videos on a design pattern I've seen so far! Thank you!
@derekbanas
@derekbanas 2 жыл бұрын
Thank you for taking the time to tell me you like them :)
@derekbanas
@derekbanas 11 жыл бұрын
I'm happy they have been able to help you :) I decided a long time ago that I wanted to make long videos, but I also wanted them to be interesting and keep the viewers attention. I'm starting to really like the final results as of late. It has been very fulfilling to work at improving my teaching style. Thanks for giving the videos a look!
@RaiyanMonsur
@RaiyanMonsur 2 жыл бұрын
You've been a huge help!
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I'm working from 6 different books to make this tutorial. I'll cover everything in the GOF book, but probably in completely different ways. I'm glad you are enjoying the tutorial
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) Think of those classes that extend ToppingDecorator as if they are layering on functionality to the Pizza composite field in the ToppingDecorator object. So, first you create the Pizza object and then add additional functionality to getDescription and getCost using the toppings. Here is another tutorial on decorator that may help further newthinktank. com/2013/02/code-refactoring-16/
@derekbanas
@derekbanas 11 жыл бұрын
I have all of the diagrams on my site. There is a link in the description for the video. I hope it helps
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) I'm doing my best to cover the more complicated topics in programming. I'm glad people are finding them useful
@derekbanas
@derekbanas 11 жыл бұрын
Thank you for watching :) I'm glad to help
@derekbanas
@derekbanas 11 жыл бұрын
I probably could have come up with a more specific optimized way to present this pattern. The ToppingDecorator could have been more simplified and then the ingredients could have done most anything. In videos I have to find an example that both demonstrates the pattern while keeping everything as simple as possible. Sometimes I get a great example and other times not so much. Sorry about that
@derekbanas
@derekbanas 11 жыл бұрын
I'm just happy that you find it useful :) Thanks for the kind words. It is just a fun hobby of mine and I expect nothing in return
@derekbanas
@derekbanas 11 жыл бұрын
It is very nice to be able to clear up a subject when others haven't helped! Thank you :)
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) Thank you for checking them out
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) i did my best with them. I found an answer for your question that I agree with here: stackoverflow. com/questions/2166632/can-you-remove-a-decorator
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I do my best to cover complicated topics in easy to understand ways. I'm glad you liked it
@dantheman52420
@dantheman52420 8 жыл бұрын
I read this pattern in Gang of Four today, was trying to figure out what the main method would end up looking like, very glad I found this video. None of my classes for my B.S. CompSci covered this stuff and I'm finding it very important for my job now.
@derekbanas
@derekbanas 8 жыл бұрын
I'm very happy that I could help :)
@0x28
@0x28 7 жыл бұрын
That is quite bizarre. Every B.S. in C.S. should cover at least 15 of the 23 patterns like in my degree. We had the GOF book and the companion book Design Patterns Explained, with an additional syllabus or 3.
@dantheman52420
@dantheman52420 7 жыл бұрын
Congrats dude
@rohanofelvenpower5566
@rohanofelvenpower5566 6 жыл бұрын
haha, MDX london here.2nd year we did Java. We didn't cover these. Just basic code and UML with related things like OOP thinking.
@derekbanas
@derekbanas 11 жыл бұрын
Thank you for taking the time to tell me I was able to help :) That is very much appreciated!
@sofiabravo9979
@sofiabravo9979 11 жыл бұрын
I love this, thank you so much! It really helps to hear this concepts from someone rather that read boring books a thousand times for each pattern. It's really cool that you do this without expecting money or any type of retribution what so ever.
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I like covering niche topics that everyone else avoids
@tautvydaskersulis7372
@tautvydaskersulis7372 3 жыл бұрын
Thanks, it's a great video explaining the concept very well. One thing that bothers me about commonly used patterns in Java is that they are often un-intuitive and do not reflect the real world as well as they could. I think the Decorator pattern is one of these. For example at 12:00 you have this line: ``` Pizza basicPizza = new TomatoSauce(new Mozzarella(new PlainPizza())); ``` I would intuitively interpret as making Mozzarella from PlainPizza and then making TomatoSauce from Mozzarella. The example below achieves the same results without decomposition and with a lot less boiler plate code, just by changing the mental model to something more intuitive and representative of real life. Are there any advantages to using the Decorator Pattern in situations like this? ``` List toppings = ArrayList(); toppings.add(new Topping("TomatoSauce", 0.35)); toppings.add(new Topping("Mozzarella", 0.5)); ToppedPizza ready = new ToppedPizza(new PlainPizza(), toppings); ``` I'm sure there are cases where Decorators are needed but I often see programmers using certain patterns to fit the solution into the their mental model when they should be reframing their mental model to match real life. What are your thoughts / experiences regarding this?
@MidasButSilver
@MidasButSilver 2 жыл бұрын
Late for a reply here, but in this case, yes, you are absolutely right. For such a simple example, a list would have done the job just fine. Its about always using the correct tool for the job and if the code was something more complicated you cannot simply rely on something like a list or array anymore. Say for example you are designing more complicated behaviour, for example enemies in a video game. Now each enemy could be different in some way: some are ranged fighters, others melee and the last group can do both, depending on the situation. You could change behaviour of each of them dynamically just with the corresponding decorator. Also in that situation a simple list just wouldn't quite do and probably fail miserably.
@alltheway99
@alltheway99 10 жыл бұрын
are you sure you wanna have "Adding dough" in Mozarella class ? (10:00)
@budguesor9222
@budguesor9222 2 жыл бұрын
Rightly pointed out. It should be present in the constructor of the PlainPizza
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) Im glad you enjoyed it
@skkar2k2
@skkar2k2 5 жыл бұрын
Bro, trust me, never find such great tutor where I can understand the design pattern so easily. You are the champ dude.
@derekbanas
@derekbanas 5 жыл бұрын
Thank you for the nice compliment :)
@derekbanas
@derekbanas 11 жыл бұрын
Sorry, but I'm not sure what you are trying to do. Send me a message on youtube, or and email derekbanas@verizon.net
@derekbanas
@derekbanas 11 жыл бұрын
Thank you very much :) I love covering niche topics that others ignore
@derekbanas
@derekbanas 11 жыл бұрын
When I start thinking about using a design pattern I normally first ask if I can accomplish making the code more readable in some other way. If I can't think of another way I use the pattern. You'll find with experience that more often then not you'll use patterns rarely. The positives in knowing them are that you'll start to find other unique ways of solving problems while writing easier to understand code.
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) I'm happy they are helping
@derekbanas
@derekbanas 10 жыл бұрын
That's funny :) Thank you for the compliment. I'm glad you are enjoying them.
@derekbanas
@derekbanas 10 жыл бұрын
You're very welcome :) Yes you could do what you described. It is really my fault because I didn't make an example that required the added flexibility this pattern provides. I tried to come up with a simple example of the pattern and in doing so I didn't get the best example. Sorry about that
@stevenfox9695
@stevenfox9695 9 жыл бұрын
Your videos are so great! I always recommend them to my friends taking the Software Design Pattern class at my university. Well done!
@ChaitanyaBhagwatChai
@ChaitanyaBhagwatChai 9 жыл бұрын
Hey Derek, i'm just going to reaffirm what others have been saying on your videos all along: thank you so much for this incredible resource for learning about design patterns. Your videos are of such incredible help while studying, both because of your excellent explanations, as well as the nature of the medium (we can replay a segment we don't understand however many times we want) and the commented code that you provide. I am a big believer of a future for internet with micro-transactions, so i just went and donated you 5 bucks. It is not much, i am a student after all, but the content you provide warrants a gesture from me :)
@derekbanas
@derekbanas 9 жыл бұрын
Chaitanya Bhagwat Showing your appreciation is more then enough for me. I'm very happy to be able to help like others have helped me in the past. Thank you for the compliment :) You're very welcome.
@khana.713
@khana.713 5 жыл бұрын
Hey man, i just gotta tell you that I love your videos and I love you. 3rd year of uni, and you still manage to help me through all the questions I have. Last semester you helped me out with Data Structures now you're helping me out with design patterns. Thank you once again, please keep this up!
@derekbanas
@derekbanas 5 жыл бұрын
That is awesome to know :) I'm happy I have been of help
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I did my best and I'm glad you liked it
@html2664
@html2664 10 жыл бұрын
Amazing! I'm from Ukraine, but your tutorial in English is easier than any of I could find in native language! Thanks!
@derekbanas
@derekbanas 10 жыл бұрын
Thank you for the compliment :)
@vincent9563
@vincent9563 7 жыл бұрын
Why don't you answer some questions on your comments?
@laleen123
@laleen123 9 жыл бұрын
Thank you so much for the excellent videos Derek, This is helping me a great deal in prepping for my CS exam! You are my hero!
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I'm glad you enjoy them
@derekbanas
@derekbanas 11 жыл бұрын
You can always override the PlainPizza class, add a topping of medium, large, Xtra large, etc. You could have all toppings have the same price and then just override the description. The rule extend what differs between toppings will steer you in the right direction
@MojSoltani
@MojSoltani 10 жыл бұрын
you're the master; never has anyone or any article or tutorial hit home design patterns to the point in such short and concise manner.
@derekbanas
@derekbanas 10 жыл бұрын
Thank you :) I'm glad you enjoyed the videos.
@derekbanas
@derekbanas 10 жыл бұрын
Thank you very much :) It is very nice of you to say that!
@robertgloverjr
@robertgloverjr 11 жыл бұрын
Excellent. Thank you so much!!!!! I have read the Gang of Four book, but it is so long that the trees get lost in the forest. Your Decorator is so clear and logical. Bravo!
@implutonium297
@implutonium297 4 жыл бұрын
Very Helpful tutorial, my first project in my Object Oriented Programming course just so happens to be creating a pizza ordering system where toppings are added using a decorator design pattern so this video was exactly what I needed! Thanks so much!
@derekbanas
@derekbanas 4 жыл бұрын
Happy I could help :)
@derekbanas
@derekbanas 11 жыл бұрын
I'm confused by your question. ToppingDecorator provides those methods to the classes that extend it
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) Im very happy that you enjoyed it
@gandhihardikm
@gandhihardikm 9 жыл бұрын
Thanks Derek for explaining decorator design pattern in such simple way... Hats off... cheers!!!
@derekbanas
@derekbanas 9 жыл бұрын
Hardik Gandhi You're very welcome :) I'm glad I could help.
@LeBadman
@LeBadman 11 жыл бұрын
You are a most excellent teacher. I usually have problems learning new (especially programming) concepts, but you made it very easy for me to understand. Your explanation is crystal clear. =)
@grandisukruth
@grandisukruth 11 жыл бұрын
First of all thank you very much. This is the best design pattern tutorials i have ever seen. We demand some more stuff from you in future :).
@doaaahmed9730
@doaaahmed9730 2 жыл бұрын
That was a brilliant example demonstrating the decorator pattern . Thanks a million!
@derekbanas
@derekbanas 11 жыл бұрын
Yes I slipped up a bit. Thanks for pointing that out
@biman1988
@biman1988 11 жыл бұрын
I always first see the running time of ur tutorials before playing. Then I feel like "ohh... so after 13 minutes the "future-me" would have learnt decorator pattern! Cool!!" Its better than counting the pages on a book n thinking "well... need to read 30 more pages to learn decorator pattern.. ahh forget it. will do later" I recently switched organization for almost double the salary (+ better work). And I owe u a big thanks since your videos were a very big help to me.
@derekbanas
@derekbanas 11 жыл бұрын
Sure I will cover the top 23 patterns described by the GOF
@derekbanas
@derekbanas 10 жыл бұрын
Thank you :) I'm very happy that I'm able to help.
@yukimushu
@yukimushu 11 жыл бұрын
Fantastic tutorial, very well presented and easy to understand. Wish more tutorials were as high quality as this one! :)
@NZ255
@NZ255 8 жыл бұрын
Man I'm hungry
@derekbanas
@derekbanas 8 жыл бұрын
+NZ255 That's funny :)
@rosasmellshaha
@rosasmellshaha 6 жыл бұрын
You have saved my ass. Exam in one week and I was not getting any of this until I discovered your videos. Hero!!!
@derekbanas
@derekbanas 6 жыл бұрын
Thank you :) Best of luck on your exams
@jorgevasquezang
@jorgevasquezang 4 жыл бұрын
I am a Senior Developer, I watched these videos from Derek 6 years ago, and yes I am watching them again :) #lifeOfDeveloper
@derekbanas
@derekbanas 4 жыл бұрын
I'm very happy to hear that I continue to help :)
@kacyraye
@kacyraye 10 жыл бұрын
Thanks a lot for providing the code. Sometimes I don't quite get things through verbal explanations, but seeing you implement it and then thoroughly going through the code afterward really helped it click. Also, I think at the end of your tutorials that involve coding, you should do one final overview of what just happened when you run the program. In this video for example, I think you could've taken us through how the objects were being wrapped.
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) it was fun to cover this topic
@derekbanas
@derekbanas 10 жыл бұрын
You are very kind :) You're very welcome
@malcomclark2261
@malcomclark2261 9 жыл бұрын
Headfirst design patterns explains things similarly but using drinks instead of pizza. You did a much better job of explaining it than the book did though.
@derekbanas
@derekbanas 9 жыл бұрын
Malcom Clark Thank you for the compliment :)
@tonyweak3842
@tonyweak3842 8 жыл бұрын
+Malcom Clark That's true! And HF DP is an excellent book for beginners, so this complement is even bigger. :-)
@nickzomchak9531
@nickzomchak9531 6 жыл бұрын
Hey Derek, why don't u just use List instead and just loop through stuff. I think the pizza example, as well as drinks one are not suitable for this pattern, cause they do not add any new behaviour, u can't do new things with pizza. even if you decorated it. Please correct me if I'm wrong.
@Messier_-82
@Messier_-82 6 жыл бұрын
You are right. This exact case is not suitable for Decorator Pattern. But this example shows well how the design works.
@nikhil2210
@nikhil2210 10 жыл бұрын
Derek, You're the best man! The range of topics you have on your channel makes me wonder if there were a team of 4-5 different experts, but its just you, unbelievable. I would love to donate on your site once i have my paycheck. For this video, like others i do have some issues with code or the way it could've been done, but i understand the focus here is understanding the pattern and not the code that is written, Thumbs UP!!, You're awesome!
@derekbanas
@derekbanas 10 жыл бұрын
Nikhil Laddha Thank you for the nice compliment :) There is no need to donate. I'm just happy that I can help.
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) God bless you as well
@jacklittle4226
@jacklittle4226 3 жыл бұрын
8 Years latter and still useful, thanks for the high quality video!
@derekbanas
@derekbanas 3 жыл бұрын
Thank you very much :)
@jandeman8410
@jandeman8410 6 жыл бұрын
I keep rewatching these series of design patterns in java. So far it helped me make my apps less violent and less complicated. Also, I love pizza! My thanks for your effort Derek. Kind Regards...
@derekbanas
@derekbanas 6 жыл бұрын
I'm very happy to hear they helped :)
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :)
@nishurangrej08
@nishurangrej08 11 жыл бұрын
This is the best example to get the idea of decorator design pattern. Thanks Derek. :)
@MrMalcovic
@MrMalcovic 6 жыл бұрын
The UML association in the diagram is *composition*, not aggregation. Aggregation uses an empty diamond.
@carlmoller807
@carlmoller807 5 жыл бұрын
Also, the Mozarella class extends ToppingDecorator. The ToppingDecorator does not extend Mozarella as the UML shows.
@enzopena1875
@enzopena1875 3 жыл бұрын
man thanks, a year trying to understand this pattern xD it was so easy
@justgao
@justgao 4 жыл бұрын
Great video! When I think about creating a pizza class with many different kinds of toppings, I might choose the builder pattern instead, so that my code for adding toppings can be linearly written instead of in the form of nested constructors. Are there any advantages of the decorator pattern over the builder pattern here?
@derekbanas
@derekbanas 10 жыл бұрын
I took a short cut. You are correct that I should have defined a Dough class like I did with TomatoSauce. I was just being a bit lazy. Sorry about that
@FabianLema
@FabianLema 10 жыл бұрын
Shouldn't the arrow in mozzarella be pointing the other way around since Mozzarella extends ToppingDecorator? (in the UML) Regardless, kudos on your videos Derek! I'm learning more here than in lecture lol
@vigneshsoap123
@vigneshsoap123 7 жыл бұрын
Awesome. Much better explanation than HeadFirstDesignPatterns. Hats off.
@Dayan2k7
@Dayan2k7 8 жыл бұрын
Derek, your tutorials are the best! Highly respected!
@derekbanas
@derekbanas 8 жыл бұрын
+Natnael “Dee” yonnatan Thank you very much :)
@constantinebindas5445
@constantinebindas5445 10 жыл бұрын
Every video from this course helps me to obtain clear understanding of dedicated pattern. Nice work! One remark about Decorator Pattern. You've forgot to implement decorators for meat stuff and olives to obtain perfect pizza :)
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I pay no attention to video count, views, or anything else. You guys seem to inform me on that stuff
@kaanapan1183
@kaanapan1183 3 жыл бұрын
Why? Why do you have a video about anything I look for? I love you bro.
@TheRedNaxela
@TheRedNaxela 6 жыл бұрын
learning for my software engineering course for university right now and have to learn all of these by heart and these videos are very helpfull thank you
@derekbanas
@derekbanas 6 жыл бұрын
I'm happy they were helpful :)
@sealwithawkwardness3951
@sealwithawkwardness3951 5 жыл бұрын
For those who don't know about SOLID principles, I recommend reading up on it. "Clean Architecture" by Robert Martin is a really good resource for this but you can just Wiki it. This design pattern is very powerful in that it directly tries to comply with the S(single responsibility) and O(open/close) of SOLID.
@facundostratocaster356
@facundostratocaster356 4 жыл бұрын
Awsome tutorials, I'm preparing for my exam with your videos!! The examples are excellent
@derekbanas
@derekbanas 4 жыл бұрын
Thank you :) I wish you the best on your exams
@derekbanas
@derekbanas 11 жыл бұрын
Great! You're very welcome :)
@derekbanas
@derekbanas 11 жыл бұрын
Thank you, but you don't have to do that. I'm not one of the guys that asks people to like and favorite everything. The fact that you find them useful is enough for me :)
@AsliAmine
@AsliAmine 11 жыл бұрын
Incredibly easy to learn !!!! THANK YOU !
@programity
@programity 11 жыл бұрын
Hey, thanks a lot for these tutorials. They're some of the simplest explanations on design patterns I've come across. :) A question: Using the decorator pattern, is it possible to add / remove decorators to / from the component after it's been instantiated? In this example, is there any way to add / remove toppings from your created pizza, or is this reliant upon been set up at instantiation?
@ablemorghon
@ablemorghon 11 жыл бұрын
Very nice. All your tutorials are great, thanks!
@Didi-bz6kt
@Didi-bz6kt 4 жыл бұрын
Hello Derek, First of all you have great videos and i really enjoy to see them. A question, this pattern is only udjusting our existing methods or i can add more methods to the decorator classes ?
@ashdavv
@ashdavv 7 жыл бұрын
Thanks for the video .. They are really helpful .. Rather than reading the GangOfFour book this is much precise and better to be done over a weekend
@derekbanas
@derekbanas 7 жыл бұрын
Thank you :) The goal was to make the GOF book easier to understand
@glacagnina
@glacagnina 10 жыл бұрын
Absolutely the best I have ever seen in video programming tutorials! You are doing a fantastic job!
@martinkohl175
@martinkohl175 8 жыл бұрын
Great video on the Decorator pattern Derek! Loved it!
@derekbanas
@derekbanas 8 жыл бұрын
+Martin Kohl Thank you :) I'm glad it helped
@bacanalienigena
@bacanalienigena 2 жыл бұрын
Thanks Derek just having this topic on my OOP Class.. and it helps a lot. Cheers mate.
@derekbanas
@derekbanas 2 жыл бұрын
Thank you very much :)
@SpMeKP
@SpMeKP 7 жыл бұрын
You should be hired as a tutor at my college. You just saved me 5 hours to say the least, while providing me with information in the most appropriate way. And this is not the first time...
@derekbanas
@derekbanas 7 жыл бұрын
Thank you :) I'm here for free when ever I can be of help
@bestof1506
@bestof1506 5 жыл бұрын
He sounds a little bit like Andy from The Office (Ed Helms)
@timleungck
@timleungck 10 жыл бұрын
Thank you so much! Clear explanation, I love you!
@babebebibobuuuuu
@babebebibobuuuuu 4 жыл бұрын
It's nearly 1 AM and I'm hungry because of you, thanks
@derekbanas
@derekbanas 4 жыл бұрын
That's funny :)
@babebebibobuuuuu
@babebebibobuuuuu 4 жыл бұрын
@@derekbanas This very Design Pattern ended up on the test this morning so thanks I guess haha
@alltheway99
@alltheway99 10 жыл бұрын
no wories, i just wantes to say something really :-) your lectures are very good
@muditmarda2150
@muditmarda2150 9 жыл бұрын
Good Stuff! All the design patterns are well explained. Thanks! :)
@derekbanas
@derekbanas 9 жыл бұрын
***** Thank you :) Your welcome
@derekbanas
@derekbanas 11 жыл бұрын
That's funny :) I'm glad you liked it
@stanststst
@stanststst 9 жыл бұрын
Hi Derek, I've been watching your tutorials since quite some time, they are very well-organized, the concepts are presented in excellent manner - uml-s, wrong-way-to-do examples and so on. Thank you for the sharing I was wondering why ToppingDecorator implements (define the method bodies) the two inherited abstract methods (getDescription getCost) if it (ToppingDecorator) is meant to be an abstract class? I guess, it is meant to be an abstract class in order to prevent instantiation of if (ToppingDecorator), which seems reasonable, to instantiate the concrete decorators. If the two methods are left unimplemented in ToppingDecorator, then they will no be overridden, but directly implemented in the concrete decorators, which will prevent the Open-Closed principle violation. I have an other question. If Pizza is injected in the ToppingDecorator "from out side", doesn't this mean that the relationship between the two is Aggregation, since the life-time of pizza is independent from ToppingDecorator concrete instance. It ,the same Pizza instance, could be injected in another decorator, for example. Thanks
@ehreut
@ehreut 11 жыл бұрын
Great Videos! very well explained, great examples, just great, thank you very much!
@henkelau
@henkelau 10 жыл бұрын
Hi Derek, thanks for a great overview of the Decorator-pattern! I just wonder, why didnt you put a Constructor in your PlainPizza-class which, accordingly to me, shoudl be reponsible for the the "Adding dough" part? Regards
@derekbanas
@derekbanas 10 жыл бұрын
henkelau The main reason is that I wrote this largely out of my head. I just tried to keep everything understandable rather then optimized. My brain normally can't do both :)
@vittoriomarino3279
@vittoriomarino3279 9 жыл бұрын
Given that ToppingDecorator is abstract and implements Pizza, is it stictly necessary to give basic getDescription() and getCost() implementation in that class? Every topping will override that behaviour, so I was just wondering if it is better to omit it or not! Whats your opinion?
@CBEpola
@CBEpola 8 жыл бұрын
+Vittorio Marino I think you are right in this case: ToppingDecorator does not need to implement those methods, since their same work is done on the protected tempPizza in the extended/concrete ToppingDecorators. But I think a tweak to this implementation, which would be better for the pattern in general, would be to [i.e:] call super.getCost() in the extended/concrete ToppingDocorator's overridden getCost(). That way, abstract ToppingDecorator#getCost() could be made more complex, but not require its code to be copy/pasted to all extended/concrete overrides. A further tweak would be to make tempPizza private for better encapsulation, which would then actually necessitate that super.getCost() I just described.
@derekbanas
@derekbanas 10 жыл бұрын
Thank you :)
Command Design Pattern
23:41
Derek Banas
Рет қаралды 282 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 213 М.
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 29 МЛН
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 120 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 1,9 МЛН
Nutella bro sis family Challenge 😋
00:31
Mr. Clabik
Рет қаралды 13 МЛН
Master Golang with Interfaces
21:54
Kantan Coding
Рет қаралды 9 М.
Decorator Pattern - Design Patterns (ep 3)
54:35
Christopher Okhravi
Рет қаралды 477 М.
Template Method Design Pattern
14:05
Derek Banas
Рет қаралды 147 М.
The Smart Way of Using the Decorator Pattern in C#
12:37
Nick Chapsas
Рет қаралды 66 М.
Simplest Decorator Design Pattern in C#
10:55
Code Radiance
Рет қаралды 25 М.
What is the Decorator Pattern? (Software Design Patterns)
19:41
Be A Better Dev
Рет қаралды 25 М.
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,2 МЛН
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 911 М.
Visitor Design Pattern
13:31
Derek Banas
Рет қаралды 276 М.
Strategy Design Pattern
11:32
Derek Banas
Рет қаралды 746 М.
마시멜로우로 체감되는 요즘 물가
00:20
진영민yeongmin
Рет қаралды 29 МЛН