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

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2022
  • 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: th-cam.com/users/CodeDecode?...
    LinkedIn : / codedecodeyoutube
    Instagram: / codedecode25
    #designpatterns #codedecode #strategydesignpattern

ความคิดเห็น • 60

  • @abhishekverma5928
    @abhishekverma5928 ปีที่แล้ว +10

    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  ปีที่แล้ว +1

      Thanks a lot Abhishek 🙂🙂

  • @ankursingh2213
    @ankursingh2213 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      Many congratulations on cracking interviews Man. 🎉🎉🎉🎉 Thanks A Lot Ankur 🙂🙂

  • @artikumari-es6ep
    @artikumari-es6ep 11 หลายเดือนก่อน

    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

  • @ramarajuramakanth2788
    @ramarajuramakanth2788 16 วันที่ผ่านมา +1

    Awesome Explanation

    • @CodeDecode
      @CodeDecode  15 วันที่ผ่านมา

      Thanks

  • @kdautomotive379
    @kdautomotive379 ปีที่แล้ว +1

    Awesome.. Interviewer asked this pattern.. Thank you.!!

  • @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.

  • @senthilrajatcs
    @senthilrajatcs ปีที่แล้ว +1

    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 ปีที่แล้ว +1

    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.

  • @vishalsepaia5893
    @vishalsepaia5893 11 หลายเดือนก่อน +1

    Very effective & to the point, thanks for all the videos. Please post your git hub repository link.

  • @travelwithgattu
    @travelwithgattu ปีที่แล้ว +1

    you are awesome.. understood this . I am using this in my project 👍👍. thank you

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว +1

      Yeah most good projects use this design pattern. It's a must for best practice implementation in java projects 🙂🙂

  • @AMITPAUL-ty1hk
    @AMITPAUL-ty1hk ปีที่แล้ว

    Well explained. Thanks for sharing.

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      You're welcome amit

  • @sayanbiswas8847
    @sayanbiswas8847 ปีที่แล้ว +1

    Keep up the good work

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      Thanks Sayan 🙂🙂

  • @pandit-jee-bihar
    @pandit-jee-bihar 11 หลายเดือนก่อน

    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.

  • @bistabil2043
    @bistabil2043 ปีที่แล้ว +2

    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 9 หลายเดือนก่อน

      How should we do this? I was thinking during runtime, get the bean of the chosen encryption using qualifier.

  • @devendra.sanghavi
    @devendra.sanghavi ปีที่แล้ว +1

    Wow ma'am you are amazing

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      Thanks Devendra 😊😊

  • @rishiraj2548
    @rishiraj2548 ปีที่แล้ว +1

    Thanks a million

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      🙂🙂 no problem Rishi

  • @mohaimanulislammahin4095
    @mohaimanulislammahin4095 ปีที่แล้ว +1

    nice topic😊😊 become a fan of your🥰

  • @jasper5016
    @jasper5016 ปีที่แล้ว

    Can you please make a video on Junits and Mockito? If possible, provide real-life examples of testing REST web services.

  • @sureshmanne7245
    @sureshmanne7245 ปีที่แล้ว +1

    Welcome back...

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      Thanks Suresh 🙂. We never went anywhere. 🙂🙂

  • @raakesh4652
    @raakesh4652 ปีที่แล้ว +1

    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👍

  • @ashutoshkumar4565
    @ashutoshkumar4565 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@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 👍👍🙂

  • @mahi2082
    @mahi2082 ปีที่แล้ว +1

    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 ?

  • @sandeepchebrolu3129
    @sandeepchebrolu3129 ปีที่แล้ว +1

    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 👍👍

  • @layarichard6739
    @layarichard6739 ปีที่แล้ว +1

    Pls have more videos on all design patterns

  • @revanthchinnu8904
    @revanthchinnu8904 ปีที่แล้ว +1

    hello madam kindly make a video on junit and mockito

  • @akashpawar3382
    @akashpawar3382 ปีที่แล้ว +1

    Please make a video on visitor design pattern

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      Sure we will create it soon

  • @amitrangwani7562
    @amitrangwani7562 ปีที่แล้ว +1

    Hi Mam, Can you please Cover Ambassador Design Pattern of Microservices?

  • @LifeTracksVlogs
    @LifeTracksVlogs ปีที่แล้ว +1

    Mam microsevices m scenario based questions p ek interview video upload kijiye

  • @hassanwhiteside4452
    @hassanwhiteside4452 ปีที่แล้ว +1

    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?

  • @shilpan5050
    @shilpan5050 10 หลายเดือนก่อน

    where will get code for above Example

  • @hamednikbakht9708
    @hamednikbakht9708 ปีที่แล้ว +1

    please create video for @transaction in spring boot

    • @CodeDecode
      @CodeDecode  ปีที่แล้ว

      Sure we will do that👍

  • @koraboinaraju9522
    @koraboinaraju9522 ปีที่แล้ว +1

    Hi can you please take one vedio webclient using webflux plz

  • @indlasubramanyam8766
    @indlasubramanyam8766 ปีที่แล้ว

    please provide git link sister