No video

Strategy Design Pattern implementation in Spring boot Java | Interview Questions | Code Decode

  Рет қаралды 24,270

Code Decode

Code Decode

Жыл бұрын

Live demo of how to Implement Strategy Design Pattern in Java in your project with real world example
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
openinapp.co/udemycourse
Course Description Video :
yt.openinapp.co/dmjvd
What is Strategy Design Pattern in java?
Strategy design pattern is a behavioral design pattern that enables selecting an algorithm at run-time. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use.
Why is Strategy Design Pattern Needed at all in java spring Boot
Typically, we tend to bundle all the algorithm logic in the host class, resulting in a monolithic class with multiple switch case or conditional statements. The following example shows the structure of one such class that supports multiple algorithms to encrypt data. family of algorithms to use.
At runtime, the code loops through the statements to perform encryption based on the client specified algorithm. The result is a tightly coupled and rigid software that is difficult-to-change.
You can imagine the consequences if you try to implement a new encryption algorithm, say TripleDES or a custom encryption algorithm.
You’d have to open and modify the Encryptor class. Also, if an existing algorithm needs to be changed, the Encryptor class will again require modification.
As you can see, our Encryptor class is a clear violation of the Open Closed principle - one of the SOLID design principles. As per the principle, new functionality should be added by writing new code, rather than modifying existing code.
You can avoid them by using the Strategy pattern
How does Strategy Design Pattern Work?
We define one abstracting Interface and multiple implementing classes
Clients can choose the algorithm to use at run time. Like adding it in properties file and reading at runtime, thereby deciding which also to pick at run time only
Each of the algorithm classes adheres to the Single Responsibility principle, another SOLID principle as they will only be concerned with encrypting data with a specific algorithm, which is currently lacking.
Participants of Strategy Design Pattern?
Common interface.
Multiple implementing standalone classes.
Create Enum with Multiple encryption types.
Strategy Factory
Real time use of Strategy Design Pattern?
Sorting class that supports multiple sorting algorithms, such as bubble sort, merge sort, and quick sort.
a file compression class can support different compression algorithms, such as ZIP, GZIP, and LZ4, or even a custom compression algorithm
data encryption class that encrypts data using different encryption algorithms, such as SHA1 SHA2 MD5, etc.
Most Asked Core Java Interview Questions and Answers: • Core Java frequently a...
Advance Java Interview Questions and Answers: • Advance Java Interview...
Java 8 Interview Questions and Answers: • Java 8 Interview Quest...
Hibernate Interview Questions and Answers:
• Hibernate Interview Qu...
Spring Boot Interview Questions and Answers:
• Advance Java Interview...
Angular Playlist: • Angular Course Introdu...
SQL Playlist: • SQL Interview Question...
GIT: • GIT
Subscriber and Follow Code Decode
Subscriber Code Decode: kzfaq.info?...
LinkedIn : / codedecodeyoutube
Instagram: / codedecode25
#designpatterns #codedecode #strategydesignpattern

Пікірлер: 60
@abhishekverma5928
@abhishekverma5928 Жыл бұрын
Wow, I felt very blessed that I found your channel. The way you teach this by following the industry standard code using spring boot is very very appreciable. Thank you for your channel, very very less instructor gave such thorough knowledge. This is the real teaching, which works for everyone, even after getting a good job. Thanks alot Ma'am for bringing such good content.
@CodeDecode
@CodeDecode Жыл бұрын
Thanks a lot Abhishek 🙂🙂
@ramarajuramakanth2788
@ramarajuramakanth2788 Ай бұрын
Awesome Explanation
@CodeDecode
@CodeDecode Ай бұрын
Thanks
@ankursingh2213
@ankursingh2213 Жыл бұрын
Thank you mam.. 🙏🙏 Because of you, I was able to switch my job and cleared all of my interviews. I literally watched a lot of your videos multiple times which really helped me a lot...
@CodeDecode
@CodeDecode Жыл бұрын
Many congratulations on cracking interviews Man. 🎉🎉🎉🎉 Thanks A Lot Ankur 🙂🙂
@bistabil2043
@bistabil2043 Жыл бұрын
Maybe I am wrong but you still have to modify existing enum thus you have to recompile. If this was implemented with if-then or switch you would have to add a single else if statement in a single file and recompile and both of these two changes (enum or if-else) are quite trivial. Open-closed principle is not satisfied in neither case. It's just that the problem is moved from one place to another, but centralized. Proper implementation (one not breaking open-closed) would require no changes to existing code - just adding the new class implementing that interface should be enough.
@lunatichigh2896
@lunatichigh2896 10 ай бұрын
How should we do this? I was thinking during runtime, get the bean of the chosen encryption using qualifier.
@senthilrajatcs
@senthilrajatcs Жыл бұрын
Mindblowing! Great effort! Crystal Clear explanation, As mentioned by others in comments I have gone through many other channel videos, Never seen this kind of masterpiece! I am watching your videos regularly, Keep doing many more videos, I have suggested your channel to my friends and even my juniors to learn.
@CodeDecode
@CodeDecode Жыл бұрын
Thanks a lot 🙂🙂. Glad to have u around Man 👍👍
@karishmarawat1359
@karishmarawat1359 Жыл бұрын
Thanks for the great content! 😊 Also, Please create complete video on spring boot project creation from start to end with all the required validation, authentication following design patterns. It would be really helpful for quick revision as well as to understand things deeply.
@CodeDecode
@CodeDecode Жыл бұрын
Sure Karishma👍
@kdautomotive379
@kdautomotive379 Жыл бұрын
Awesome.. Interviewer asked this pattern.. Thank you.!!
@CodeDecode
@CodeDecode Жыл бұрын
Thanks 🙂🙂
@vishalsepaia5893
@vishalsepaia5893 Жыл бұрын
Very effective & to the point, thanks for all the videos. Please post your git hub repository link.
@devendra.sanghavi
@devendra.sanghavi Жыл бұрын
Wow ma'am you are amazing
@CodeDecode
@CodeDecode Жыл бұрын
Thanks Devendra 😊😊
@travelwithgattu
@travelwithgattu Жыл бұрын
you are awesome.. understood this . I am using this in my project 👍👍. thank you
@CodeDecode
@CodeDecode Жыл бұрын
Yeah most good projects use this design pattern. It's a must for best practice implementation in java projects 🙂🙂
@artikumari-es6ep
@artikumari-es6ep Жыл бұрын
Hi, thanks a lot for making these videos. Please make video on all design patters of java, with example as you have explained in this video
@tejeswarpala2841
@tejeswarpala2841 Жыл бұрын
after watching/reading about the pattern from other sources on internet i thought i got it. but after watching your video only i understood what problem this pattern solves, how it can be applied in an enterprise grade project. Excellent work. I have never seen this type of explanation. 🔥🔥🔥 i like the way the below things are covered in your video. what is it why it is used instead of if else based approach. how it is used debugging the usage.
@pandit-jee-bihar
@pandit-jee-bihar Жыл бұрын
The identity provider or Authentication Server accepts the JWT token and decodes it to find the algorithm used in the header. IDP uses the same algorithm for token signature validation, it's a use case for Strategy Design Patterns as the algorithm is not pre-decided.
@AMITPAUL-ty1hk
@AMITPAUL-ty1hk Жыл бұрын
Well explained. Thanks for sharing.
@CodeDecode
@CodeDecode Жыл бұрын
You're welcome amit
@sayanbiswas8847
@sayanbiswas8847 Жыл бұрын
Keep up the good work
@CodeDecode
@CodeDecode Жыл бұрын
Thanks Sayan 🙂🙂
@mohaimanulislammahin4095
@mohaimanulislammahin4095 Жыл бұрын
nice topic😊😊 become a fan of your🥰
@CodeDecode
@CodeDecode Жыл бұрын
Thanks 🙂🙂
@mahi2082
@mahi2082 Жыл бұрын
Awesome explanation. Requesting you to do other patterns i had faced Adaptor, Command ,Template design pattern these are asked in jpmorgan and goldman sach. All finance companies concentration on these i hope you will respond to this chat. Thanks for your effort and time.
@CodeDecode
@CodeDecode Жыл бұрын
Sure Mahi we will try to upload them . Was it asked bcz u used them in any project or out of blue moon they asked random patterns ?
@raakesh4652
@raakesh4652 Жыл бұрын
Mam pls complete last JUnit series... JUnit for controller n all... Those are pending...thank u.. gr8 work.. Keep up.
@CodeDecode
@CodeDecode Жыл бұрын
Sure 👍👍 we will do that👍
@sureshmanne7245
@sureshmanne7245 Жыл бұрын
Welcome back...
@CodeDecode
@CodeDecode Жыл бұрын
Thanks Suresh 🙂. We never went anywhere. 🙂🙂
@rishiraj2548
@rishiraj2548 Жыл бұрын
Thanks a million
@CodeDecode
@CodeDecode Жыл бұрын
🙂🙂 no problem Rishi
@sandeepchebrolu3129
@sandeepchebrolu3129 Жыл бұрын
Thanks for the Explanation, one Q - at 16:03 when component is loaded and the constructor is called how is the treeset value being passed ?
@CodeDecode
@CodeDecode Жыл бұрын
It's constructor injection. If u see it's @autowired 👍👍
@jasper5016
@jasper5016 Жыл бұрын
Can you please make a video on Junits and Mockito? If possible, provide real-life examples of testing REST web services.
@ashutoshkumar4565
@ashutoshkumar4565 Жыл бұрын
should this playlist contain more videos? of other common patterns?
@CodeDecode
@CodeDecode Жыл бұрын
Sure Ashutosh. Can you please let us know which all patterns you need. We will put videos on them too
@ashutoshkumar4565
@ashutoshkumar4565 Жыл бұрын
@@CodeDecode ​ Behavioural patterns like Observer pattern, creational pattern like builder, structural pattern like adapter, bridge, decorator, facade, some J2ee patterns . This is just so that the playlist is the one place to go for common design patterns. Appreciate your work. Amazing channel
@CodeDecode
@CodeDecode Жыл бұрын
Sure Ashutosh we will create more dp then. Builder is there in this playlist though. Check 32.50 min of the first part. Lemme know if you still can't find it 👍👍🙂
@hassanwhiteside4452
@hassanwhiteside4452 Жыл бұрын
I do have a problem, there is NullPointerException in my application. My encryptionTypesSet argument in Autowired method EncryptionFactory is null and therefore I cannot create any strategy. Does anyone have an idea what the cause could be?
@CodeDecode
@CodeDecode Жыл бұрын
You forgot @autowire on constructor of factory class?
@layarichard6739
@layarichard6739 Жыл бұрын
Pls have more videos on all design patterns
@CodeDecode
@CodeDecode Жыл бұрын
Sure 👍👍
@revanthchinnu8904
@revanthchinnu8904 Жыл бұрын
hello madam kindly make a video on junit and mockito
@akashpawar3382
@akashpawar3382 Жыл бұрын
Please make a video on visitor design pattern
@CodeDecode
@CodeDecode Жыл бұрын
Sure we will create it soon
@LifeTracksVlogs
@LifeTracksVlogs Жыл бұрын
Mam microsevices m scenario based questions p ek interview video upload kijiye
@CodeDecode
@CodeDecode Жыл бұрын
Sure 👍👍
@amitrangwani7562
@amitrangwani7562 Жыл бұрын
Hi Mam, Can you please Cover Ambassador Design Pattern of Microservices?
@CodeDecode
@CodeDecode Жыл бұрын
Sure 👍👍
@hamednikbakht9708
@hamednikbakht9708 Жыл бұрын
please create video for @transaction in spring boot
@CodeDecode
@CodeDecode Жыл бұрын
Sure we will do that👍
@koraboinaraju9522
@koraboinaraju9522 Жыл бұрын
Hi can you please take one vedio webclient using webflux plz
@CodeDecode
@CodeDecode Жыл бұрын
Sure 👍👍
@shilpan5050
@shilpan5050 11 ай бұрын
where will get code for above Example
@indlasubramanyam8766
@indlasubramanyam8766 Жыл бұрын
please provide git link sister
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 6 МЛН
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 28 МЛН
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 31 МЛН
Strategy Design Pattern - design patterns (ep 3)
19:57
BBarters
Рет қаралды 56 М.
What is the Strategy Pattern? (Software Design Patterns)
13:18
Be A Better Dev
Рет қаралды 56 М.
Strategy Design Pattern
11:32
Derek Banas
Рет қаралды 748 М.
3.5 Years Experience || Real Wipro java spring boot Interview Questions
41:25
JAVA INTERVIEW BUDDY
Рет қаралды 14 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 6 МЛН