How to Implement the Decorator Pattern in C#

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 9

  • @Takayaki42
    @Takayaki42 Год назад

    These tips on design patterns are lit, mr. Pat!
    Thank you so much!

  • @cverde1234
    @cverde1234 Год назад

    I remember discussing this pattern with you back in 2018 after a team member put try...catch clauses in nearly all methods 😂. Keep up the good work Patrick 👌😁

    • @TechWithPat
      @TechWithPat  Год назад

      I remember... 🙂

    • @MichaeldeGans
      @MichaeldeGans 2 месяца назад

      Won’t the SaveFileAsync original method be called twice when the size is over a megabyte this way?

  • @williamliu8985
    @williamliu8985 Год назад

    Nice explanation! I have one question, if I use DI to get the instance of service, and all these three services implement the same interface, how to resolve them then? thanks!

    • @TechWithPat
      @TechWithPat  Год назад

      William, you can use DI to get the initial instances, but if you need to get instances dynamically, that could be difficult to achieve. Overall, I think the best way would be to use a Factory.

    • @williamliu8985
      @williamliu8985 Год назад

      @@TechWithPat Thanks for your reply!

  • @witChaos
    @witChaos Год назад

    Don't you break the open close principal with the second example? Would it be better to made this size check in the implementation of Resize class, before return the SaveFile?

    • @TechWithPat
      @TechWithPat  Год назад

      That's a valid option, I hesitated to include this check in the Resize class.