The Rules Engine Design Pattern with C#

Поділитися
Вставка
  • Опубліковано 24 лип 2024
  • Hi guys, today we are going to talk about the rules engine pattern, a design pattern that can help follow the Open-Closed Principle. We will see what problems can solve and when and how to use it with examples.
    00:00 : The problem we are trying to solve
    03:39 : Implementing the Rules Engine
    14:05 : Adding order to our rules

КОМЕНТАРІ • 19

  • @mihaiga
    @mihaiga Рік тому +4

    Very concise video, great job. My recommendation would be to encapsulate the ordering inside the rule engine since using an Enum for ordering is not very clean and does not communicate to other developers that there is a dependency between the Enum and the business logic. An improvement for real-world scenarios could be to use the strategy pattern and define a list of ordered rules as a strategy that can be applied. Keep up the good work and I hope to see your channel grow!

  • @codingwithtien
    @codingwithtien Рік тому +2

    I had a live coding interview a few years ago and they asked me to solve precisely this topic. Thanks for your video.

    • @spyroskatsios
      @spyroskatsios  Рік тому

      You are welcome! Hope you did well in the interview!

  • @ChequeWriter
    @ChequeWriter 9 місяців тому

    Good video.

  • @atarconcet
    @atarconcet 5 місяців тому

    Good solution, however, I feel that the DiscountRule enum will break the open-closed principle because you will need to modify the enum every time you add a Rule. I would still vote for the order, even if you can assign IDs with gaps, such as ID=100, ID=200. This could give you the freedom to add up to 99 possible rules in between. However, that option isn't perfect either, as it would force you to anticipate what other rules might be added. Nonetheless, it's a good topic and solution. Thanks.

    • @spyroskatsios
      @spyroskatsios  5 місяців тому

      I like your solution! Thanks for your kind words!

  • @nsa-iwillneverhityou
    @nsa-iwillneverhityou 8 місяців тому

    nice video.

  • @manchusandy1
    @manchusandy1 9 місяців тому

    I want to copy the code. Do you have github link for this ?

  • @zefur321
    @zefur321 3 місяці тому

    can i keep rules in database ?

    • @spyroskatsios
      @spyroskatsios  3 місяці тому

      Hi! I suppose you could, but in what form are you going to store them?

    • @zefur321
      @zefur321 3 місяці тому

      @@spyroskatsios now i try to study Drools. but dont know how to install and integrate with eclipse (java).
      so i not sure c# also have rule engine that can keep rules in configuration file, xml or database or not?

  • @georgekalogeropoulos1813
    @georgekalogeropoulos1813 Рік тому +2

    Honestly the second version is way more complex 😆

    • @spyroskatsios
      @spyroskatsios  Рік тому +3

      You mean the one with the ordering or the one with the rules engine?

    • @MiningForPies
      @MiningForPies Рік тому +1

      Yes it is, when you only have a couple of rules.
      When you have 10 or 20 or 50 it’s a lot less so, especially around unit testing.

    • @spyroskatsios
      @spyroskatsios  Рік тому +1

      @@MiningForPies Exactly! And that's a trade off with demos around ddd and design patterns. You can't have a complex logic since it's a demo, but they look kind of redundant without it!