Template Method Pattern - Design Patterns (ep 13)

  Рет қаралды 94,791

Christopher Okhravi

Christopher Okhravi

6 жыл бұрын

Video series on Design Patterns for Object Oriented Languages. This time we look at the Template Method 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
► Show your support using Patreon :D
patreon.christopherokhravi.com
► SOLID Design Principles
• SOLID Design Principles
• SOLID Design Principle...
► Products I recommend:
geni.us/71ZXF

Пікірлер: 123
@namanvaishnav4307
@namanvaishnav4307 25 күн бұрын
How someone can be relevant after 6 years!! Amazing!!
@SelimAjimi
@SelimAjimi 6 жыл бұрын
If I can tell you how much I appreciate the work you are doing... you will not believe me. Please continue and don't stop.
@delucabruno
@delucabruno 6 жыл бұрын
Please continue with this serie, your videos are awesome!
@cghfdsxfcbhjhgfdsdfg
@cghfdsxfcbhjhgfdsdfg 3 жыл бұрын
You are the man, I've never looked forward to a lecture before
@rithikareddy2919
@rithikareddy2919 6 жыл бұрын
Your videos are amazing!! Thanks a lot! This series has helped me a lot in understanding Design Patterns! :D
@ameeralikhan9288
@ameeralikhan9288 5 жыл бұрын
Man you are Genius just when i was thinking this look similar to Strategy pattern you covered that part just then.
@agustinchavez4836
@agustinchavez4836 6 жыл бұрын
Your videos are one of the coolest things I found on youtube. Every time they present a design pattern in my university I watch one of your videos. You came to Argentina. Thank you! (Sorry my english is bad)
@karimel-shindy9655
@karimel-shindy9655 6 жыл бұрын
Awesome, I really love your way of explaning things. BTW you helped me a lot to understand a lot of concepts and terms which helped me to pass the technical exam and interview of a new job. thanks a lot Christopher
@nicolabombace2004
@nicolabombace2004 6 жыл бұрын
I totally agree with your point about the Strategy Pattern! very well explained
@JohnWayne-nc6yq
@JohnWayne-nc6yq 6 жыл бұрын
Youre amazing man, I wish you could be my academician for my patterns lecture. 2 Days later I got Final exam and I finally understood how do many design patters work. Thanks for all, I wanna meet you some day cause your energy is perfect.
@kasozivincent107
@kasozivincent107 4 жыл бұрын
I love your accent. In addition you are my hero when it comes to design patterns
@marcelgonzalez1376
@marcelgonzalez1376 Жыл бұрын
This was a fantastic lecture. The lecturers at my university could learn a thing or two from you about how to teach. Many thanks!
@Defiguss
@Defiguss Жыл бұрын
Thank you so much for your amazing work! Really has helped me to grasp the concept of design patterns and see how useful they are. Thanks to you, my code became cleaner, more universal and more efficient. This is definitely the best design-patterns-explaining channel I have come across.
@MyroslavOhorodnyk
@MyroslavOhorodnyk 4 жыл бұрын
This one was pretty complex for me up until the code example. Thanks for adding that one! And as always thanks!
@kevinbenavides92
@kevinbenavides92 6 жыл бұрын
Thanks Chris! Keep up the great work.
@vaibhavkumargandikota4714
@vaibhavkumargandikota4714 3 жыл бұрын
Appreciate your efforts for providing this quality content !
@chamroeunuon4446
@chamroeunuon4446 6 жыл бұрын
Thank Christopher for creating this tutorial. It's make me more understand about design patterns: )
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
I’m glad to hear :)
@mikhailbisserov8017
@mikhailbisserov8017 6 жыл бұрын
Kudos for pointing out that Template Method is a good case of Open/Closed principle usage. My understanding is that in ASP NET WebForms they use Template Method so that developer could hook his code into page life cycle, because developer inherits his code-behind class from base Page class there. Even though they call it "events", developer doesn't have to use events subscription mechanism. But developer doesn't have to add "override" either. Ok, I'm not sure if that's canonical Template Method pattern in action.
@saudnaeem
@saudnaeem 6 жыл бұрын
Excellent explanation, helped a lot. thanks btw
@muhannadimad2070
@muhannadimad2070 3 жыл бұрын
you are the best who explain design pattern , thank you man ......
@dhinahappybank1377
@dhinahappybank1377 6 жыл бұрын
Good Job, Chris! Thanks!
@mangeshphanse2132
@mangeshphanse2132 5 жыл бұрын
Very good video. Cleared the concept of template method. Keep it up
@harishankar-cz9tx
@harishankar-cz9tx 2 жыл бұрын
I use "Ruby On Rails" on daily basis. Didn't know it's very neat use of Template Method Pattern. Thanks :)
@claudiocito9057
@claudiocito9057 5 жыл бұрын
thank you so much, this videos are so helpful!!
@meratube007
@meratube007 6 жыл бұрын
like your passion for teaching !! thanks :)
@vahabghadiri
@vahabghadiri 4 жыл бұрын
That was absolutely awesome!!!! VERY VERY THANKS! p.s. i am eagerly waiting for your UML basics or maybe tips video.
@LavGupta08
@LavGupta08 6 жыл бұрын
Awesome video. Thank you so much again :)
@jatinkumar4410
@jatinkumar4410 2 жыл бұрын
Amazing explanation. Hats off to you...
@Timboson
@Timboson 4 жыл бұрын
Awesome explanation. You are my hero
@sv6562
@sv6562 Жыл бұрын
Awesome very clearly explained and great to use a board to explain
@ricardcutzh
@ricardcutzh 5 жыл бұрын
nice explanation dude! thanks a lot!
@marceloleoncaceres6826
@marceloleoncaceres6826 10 ай бұрын
Another great video, thanks for sharing
@AndreiMeius
@AndreiMeius 4 жыл бұрын
The whole point of this pattern is to be able to do Record r = new User; r->save(); so records are uniformely treated. User u = new User doesn't show the power of the pattern.
@santiagolosa4751
@santiagolosa4751 6 жыл бұрын
Super usefull thank you so much!
@enjoyyourlife3989
@enjoyyourlife3989 2 жыл бұрын
Great video! Thanks very much!
@bouchradahamni9881
@bouchradahamni9881 5 жыл бұрын
great explication !!!
@unknow8819
@unknow8819 5 жыл бұрын
Thank You, you saved my exam
@aymanshaawat
@aymanshaawat 6 жыл бұрын
Like before watching I was waiting for this pattern
@munjal55555
@munjal55555 4 жыл бұрын
really nice explanation about strategy vs template
@ChristopherOkhravi
@ChristopherOkhravi 4 жыл бұрын
Appreciated.
@alecc8231
@alecc8231 4 жыл бұрын
Template pattern could be substituted with a Strategy: A class "A", which implements a 'Template()' method only, and has a dependency on other classes that are needed in that method. They would implement "INeededOperations". So the usage would be: INeededOperations neededOps1 = new ConcteteOperations1(); //Needed by class A operations implemented. object a = new A(INeededOperations); //dependency injected with needed operations. a.Template(); //actual method called, which used to be an abstract template method. This way, only Class A is there and no other variations of class A exist because we need to use the 'Template()' method. But multiple variations of the INeededOperations are implemented. Instead of the abstract class using ghost functions, this way 'real' injected functions would be used. By the way, I totally love these series. Way to go Christopher!
@iljastepanov2627
@iljastepanov2627 2 жыл бұрын
I have been using this one for years without even knowing it
@abdeltube772
@abdeltube772 6 жыл бұрын
It must has taken a lot of effort to prepare and edit the video, thank you!
@onkarvidhate1564
@onkarvidhate1564 11 ай бұрын
in the definition of template pattern, they have used word "operation" because 'operation' term is equivalent to class method. And because we are only templating a method and not a whole class, author might have thought to emphasis more on it.
@Endomorphism
@Endomorphism 4 жыл бұрын
23:27 we can even use strategy pattern an other way inject strategy and Template Method will call *strategy.DoOperationsInSteps(this)* it admire composition over inheritance.
@Cmppayne26542
@Cmppayne26542 6 жыл бұрын
I hope that in the future you will cover all patters from the GoF instead of just the ones covered in the heads first book
@_aibeats
@_aibeats 5 жыл бұрын
I believe this pattern can be implemented without inheritance! Anyway, your videos are great.
@shynggyskassen942
@shynggyskassen942 2 жыл бұрын
Thank you!
@bragoen
@bragoen 6 жыл бұрын
The funny thing is that when I learned about abstract classes in my very junior days, I thought they were meant for that very reason, provide base implementations and hooks. Then I learned about this pattern and I was like "wait, isn't it obvious?"
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Hehe :) In some sense it indeed is. And in some sense I guess one could argue that all of the GoF design patterns are more or less obvious ideas that anyone who carefully contemplates OO will come up with on their own. But whether these ideas were then given names so that we can more easily talk about them or so that authors can sell more books I do not know :) :) Thanks for watching and for sharing! Interesting and relevant perspective.
@bragoen
@bragoen 6 жыл бұрын
Oh absolutely, a big part of pattern usefulness is to create a common language to share ideas of design (or make money), but still they're also a way of teaching usage and put some structure for those who are lost in the big mess of possibilities that is an OO language. Everyone is different but when I learned about those around Y2K this one was basically the only one where I sort of had made gotten the idea of "wait, is there any other way ?"
@jonathanshelvey4580
@jonathanshelvey4580 3 жыл бұрын
@@ChristopherOkhravi Yeah I think everyone at some point has accidentally reinvented a design pattern before they knew what a design pattern was
@vikas5951
@vikas5951 2 жыл бұрын
Good Job!!!
@aygulismayilova8414
@aygulismayilova8414 2 жыл бұрын
Thank you so much
@kevinshi8117
@kevinshi8117 6 жыл бұрын
brilliant!
@deathangel908
@deathangel908 6 жыл бұрын
A good example of template pattern would be any lifecycle component. e.g. reactjs component or android component where frameworks calls lifecycle hooks like `onCreate` `onDestroy`. Also I guess most of this use cases break single responsibility principles. As your `User` model is responsible for holding data and saving it. 38:40 good use of `trim`
@andriikukuruza6844
@andriikukuruza6844 3 жыл бұрын
awesome!
@B-Billy
@B-Billy 6 жыл бұрын
"HERO POSTER" haha... I like it :)
@sushmap8844
@sushmap8844 5 жыл бұрын
marking save() method as final makes more consistent .
@Ranjith_P
@Ranjith_P 5 жыл бұрын
Firstly Thanks for your videos they are amazing to clear concepts up . I am actually from Database background and learning Object oriented programming ( Java mostly ) out of interest . One question I had - what is this virtual keyword mentioned in the concept of hooks while implementing the Template method pattern ?
@ShubhamGupta3110
@ShubhamGupta3110 6 жыл бұрын
Can you share some detailed thoughts on "Composition over Inheritance". Just a thought, can't we do what template pattern does using Decorator and Strategy if I am sticking to Composition over inheritance principle. Though I think it would be asking too much from the end user to use features of Abstract Class (used in your example.)
@oleksandr.pastukhov
@oleksandr.pastukhov 6 жыл бұрын
Well done, Christopher! As always! BTW, do you plan to continue your series of videos about the books you have finished to read?
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Thank you :) Much appreciated :) Do you mean the videos on non-programming books?
@oleksandr.pastukhov
@oleksandr.pastukhov 6 жыл бұрын
Christopher Okhravi yes, this is exactly what I meant.
@amank2410
@amank2410 6 жыл бұрын
Excellent :) .....
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
:) I’m glad to hear. Thanks for watching :)
@CarlosGonzalezRubio
@CarlosGonzalezRubio 6 жыл бұрын
If possible I would like to see a video of the design pattern called mediator. Thanks for sharing your knowledge!
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
It will absolutely come :) If I would guess I would however say that it probably drops after New Years rather than before. But I hope that doesn’t cause any troubles for you 🙂🙂 Thanks for the encouragement!
@vjhfdtcydshutd
@vjhfdtcydshutd 3 жыл бұрын
@@ChristopherOkhravi Did we add this? What is the name of the video title if it's part of this playlist?
@kutanarcanakgul5533
@kutanarcanakgul5533 5 жыл бұрын
2:18 Cracked me "This is aah"
@mauriciopartnoy2789
@mauriciopartnoy2789 Жыл бұрын
I remember using this pattern (without knowing it's name) a while back while making a tweening system. The abstract tweening class had a method that calculated a 0-1 clamped value along a curve, and then called an abstract method for concrete tweens to implement using that clamped value as a parameter. In the end each concrete tween had a simple Evaluate(float t); to control animation. It worked great! Great tutorial series by the way! You are a great teacher :)
@orestis131
@orestis131 2 жыл бұрын
Great
@Gusse1234554321
@Gusse1234554321 4 жыл бұрын
22:24 Ahaha love it!
@SunggukLim
@SunggukLim 6 жыл бұрын
Nice video as always(especially very good example!) :) btw, do you have podcast channel?
@p...p
@p...p 6 жыл бұрын
hook method and method overriding are the same term that you are referring to or they are different things ?
@jurekszymanski4843
@jurekszymanski4843 3 жыл бұрын
Become teacher on UDEMY and let others understand the patterns. I would be the first to buy the course.
@divyeshkumarbalar7732
@divyeshkumarbalar7732 5 жыл бұрын
can you explain dependency injection concept in a separate video please....
@m.alexander3071
@m.alexander3071 5 жыл бұрын
Do I get that right? Hmmm... The Strategy pattern abstracts over different algorithms that have a somewhat same behaviors but (possibly) strongly different structure (I think about sort algorthms "bubble sort" vs. "sorting networks"). The TemplateMethod Pattern would more for a specifically structured algorithm, that have only view portions different - like... a bubblesort where you templatized the type and the type specific swap of the things that are sorted.
@benjamincisneros797
@benjamincisneros797 6 жыл бұрын
I like the way you explain the design patterns. Just a suggestion, you can use {A} for abstract classes and methods instead of italics or other styles as UML for Java programmers book suggests. By Robert C. Martin.
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Thank you for the great suggestion! Not sure what I was thinking when I tried to write in italics :D
@kareemjeiroudi1964
@kareemjeiroudi1964 4 жыл бұрын
@@ChristopherOkhravi Handwritten italics 😅
@ganeshkumbhar2499
@ganeshkumbhar2499 6 жыл бұрын
Can we say Template pattern lies in between bridge pattern and strategy pattern, in terms of coupling?
@lazarbecic2199
@lazarbecic2199 Жыл бұрын
22:20 Nice bonk XD
@jainamshah3993
@jainamshah3993 3 жыл бұрын
Simple application of template method pattern is in Instagram where template is the same but content(image, reel, etc) are different. PS: This is just an example.
@ashwingaikwad128
@ashwingaikwad128 5 жыл бұрын
17:55 uuuaahh :P :P
@leomeror
@leomeror 3 жыл бұрын
24:00 I think I agree, that composition should be favored over inheritance, but I have a question regarding this case. In a scenario where we want to use Template Method Pattern, but we want to have the ConcreteClass inherit from say class Animal, couldn't we just let AbstractClass inherit from Animal and then ConcreteClass inherit from AbstractClass as usual, or is that problematic? (This is regarding the "spot for inheritance" 24:36) I understand that composition can be used way more freely than inheritance in languages that do not support multiple inheritance (like Java), but at least for the Template Method Pattern, I don't yet see how letting AbstractClass inherit from the Class you wanted ConcreteClass to inherit from is an issue. Also it feels like there should be a way to have something like the Template Method Pattern in interfaces that isn't a Startegy Pattern, but I can't really think of it right now... Awesome video btw, much support :)
@timothy6966
@timothy6966 5 жыл бұрын
Funny. I’ve been building a way to run optimizations on models where exact implementations could vary. I thought I was using the strategy pattern, like a boss, turns out I created a template function letter by letter. Including the lifecycle hooks. The more I learn about design patterns, the more I realize it’s all just common sense. If you understand object orient programming - *really* understand - you know design patterns.
@almahdc
@almahdc 3 жыл бұрын
Thank you, Christopher! I have one question though, does the template method violate SRP actually?
@Baroquepassion
@Baroquepassion 3 жыл бұрын
I guess not if you think about the responsibility of the template method as "organise the structure of the algorithm correctly". Which I guess comes back the whole discussion about when the template method would be an appropriate pattern - it only makes sense if the algorithm has a predefined structure which has to be preserved. At least, that's how I see it.
@ivanpallares9039
@ivanpallares9039 3 жыл бұрын
Regarding differences between Bridge and Strategy, isn't it that in Bridge, the Implementor part is more like Value Objects, whereas Strategy works with services/algorithms? I am just learning about patterns these days so it might be pretty dumb what I just said.
@hitendrarawat9590
@hitendrarawat9590 3 жыл бұрын
few things are misleading/wrong, In strategy pattern behavior is injected in run time, i.e. the iAlogo's Concrete class has a behavior; whereas in template method a template is extended to get a new behavior at the compile time.
@divyeshkumarbalar7732
@divyeshkumarbalar7732 5 жыл бұрын
I have a very bad habit of watching videos at 2xSpeed; and while watching, it seems like you are having strokes..... joke a part.. Good job, keep it up
@abhishekbansal9472
@abhishekbansal9472 Жыл бұрын
How is this different from a simple abstract class or an interface?
@eduardojreis
@eduardojreis 3 жыл бұрын
Can we say the bridge method is a generalization of the Template Method?
@SalahLFC11
@SalahLFC11 4 жыл бұрын
"Template method defines skeleton of algorithm in an operation" I think here opration = method. I heard these words interchangably in my classes.
@nitin_puranik
@nitin_puranik 10 ай бұрын
Chris, the subtitles (cc) in this video is being detected as Dutch. Could you please change the cc setting to English so that non native English speakers can follow along better? I think it must be a simple setting in your KZfaq studio. Thanks!
@ameeralikhan9288
@ameeralikhan9288 5 жыл бұрын
Please cover Chain of responsibility pattern i have tough time understanding it only you can help :) Also Mediator, Visitor and Memento please
@quintonwilson8565
@quintonwilson8565 3 жыл бұрын
I'm not getting the whole "hook" aspect. Why would you have a concrete method that's empty? If the sub class doesn't override the empty hook method, you have no implementation anywhere that's ran. What's that point of calling the hook method from the templateMethod() if the hook method may never provide any behavior? Wouldn't templateMethod() have to check if an implemented hook method somewhere, did something.
@kevinchun7058
@kevinchun7058 4 жыл бұрын
Don't call me, I will call you.
@momedalhouma14
@momedalhouma14 5 жыл бұрын
what it remains: chain of responsability, Command, Interpreter, Mediator, Memonto, Visitor design patterns. please please please.
@GabrielVasile
@GabrielVasile 5 жыл бұрын
Command is already done. You can find it here kzfaq.info/get/bejne/b9dxaM6oncrHg4k.html
@umutozkan
@umutozkan 6 жыл бұрын
Good conceptual info but you can find better real time example.
@StevenLightning
@StevenLightning 3 жыл бұрын
Huh, here’s a pattern I’ve used without knowing it.
@adriangodoy4610
@adriangodoy4610 3 жыл бұрын
rule1 of software developer. It's never going to change= next week will change
@YaroslavShcherban
@YaroslavShcherban 3 жыл бұрын
1k likes :)
@cristian91re
@cristian91re 3 жыл бұрын
HoF, functional programming is so much simpler...
@andrejuha164
@andrejuha164 3 жыл бұрын
Paterns exist also in functional programming. Doesn't matter if is an object or function . Also you need sometimes use inheritence
@ambarishkapil8004
@ambarishkapil8004 3 жыл бұрын
Never read about the Template Pattern, but the moment Chris read the definition I paused the video for a minute to think and came up with the exact uml diagram and the code. The rest of the video was just like reinforcing my idea...guess I am really good at this stuff
@fmpranav
@fmpranav 3 жыл бұрын
Captain Jack Sparrow.!! 😉😂
@kevintyrrell7409
@kevintyrrell7409 6 жыл бұрын
Really on the long side man. I feel like the design pattern could be expressed much more succinctly. For example on Singleton, I could say that the theory is having only one object instantiated at a time. That in multithreaded applications it becomes harder. Then speak of when it should be used and why not. Then at the end show a tiny bit of UML and pseudocode. Just my two cents
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Super good two cents. Much appreciated :) I need to learn to control my ramblings and rants :) Thanks for watching and for the feedback 🙏 😊
@oceanhugstheshore
@oceanhugstheshore 6 жыл бұрын
I disagree. Short explanations omit a lot of underlying concepts and personally I find it great, that Chistopher describes the patterns clearly and in details. I also like the fact, that the most important ideas are repeated several times during the video, as it helps to remember better. Christopher, thank you for these great videos, they're so much better than our university lectures! :)
@iLight33r
@iLight33r 5 жыл бұрын
@@oceanhugstheshore Agreed!
@boblim623
@boblim623 4 ай бұрын
learn English and learn Design Patterns. thx from China
@soorathea
@soorathea Жыл бұрын
All your other vids are good, but this one too wordy so plz start at 42:00
@emastojanovska6063
@emastojanovska6063 3 жыл бұрын
I should pay you instead of uni
@JosiahWarren
@JosiahWarren 4 жыл бұрын
man 1 hour for the Template pattern ???? Really ?
Composite Pattern - Design Patterns (ep 14)
1:11:23
Christopher Okhravi
Рет қаралды 143 М.
Proxy Pattern - Design Patterns (ep 10)
37:35
Christopher Okhravi
Рет қаралды 161 М.
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 111 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 104 МЛН
Why Use Design Patterns When Python Has Functions?
23:23
ArjanCodes
Рет қаралды 101 М.
Bridge Pattern - Design Patterns (ep 11)
52:04
Christopher Okhravi
Рет қаралды 144 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 211 М.
8 Design Patterns | Prime Reacts
22:10
ThePrimeTime
Рет қаралды 392 М.
Command Pattern - Design Patterns (ep 7)
39:12
Christopher Okhravi
Рет қаралды 266 М.
Abstract Factory Pattern - Design Patterns (ep 5)
25:54
Christopher Okhravi
Рет қаралды 309 М.
State Pattern - Design Patterns (ep 17)
1:20:30
Christopher Okhravi
Рет қаралды 148 М.
Covariance and Contravariance
13:31
Christopher Okhravi
Рет қаралды 11 М.
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,2 МЛН