Simplest Strategy Design Pattern in C#

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

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

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

    Correct me if I'm wrong.. When u start using switch case then its more like factory.. Strategy should remove that switch case..

    • @CodeRadiance
      @CodeRadiance  4 ปีที่แล้ว

      Yeah I understand why you think so. Switch case is just to select a suitable strategy and not to return any specific object implementation like we do in a factory.

    • @starman9000
      @starman9000 4 ปีที่แล้ว

      @@CodeRadianceYou could use reflection to pick the appropriate strategy at run time.

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

      @@starman9000I wouldn't use reflection because it's too costly for that, not to mention the increased complexity and worse maintainability.

    • @sunnypatel1045
      @sunnypatel1045 3 ปีที่แล้ว

      @@brunocastro754 Agreed mate. I would have a class that will enumerate all the strategy and then invoke it in the code via DI. Hence not breaking any OCP.

  • @nayj3l
    @nayj3l 4 ปีที่แล้ว +5

    lol! it says simplest strategy but u just used a very complex and overwhelming example

  • @hosseinhosseini717
    @hosseinhosseini717 3 ปีที่แล้ว

    thanks