Use Null Object Pattern in Your Rich Domain Model

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

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

  • @tarsala1995
    @tarsala1995 Год назад +10

    I rarely watch videos twice. This one opened my eyes. I think your videos are reminding us how we should look at the code.

    • @zoran-horvat
      @zoran-horvat  Год назад +2

      Thank you for your comment. I am glad to hear the video was helpful.

  • @codingbloke
    @codingbloke Год назад +13

    Excellent presentation. Well balanced. None of the "Your doing X wrong!!" hysterics here.

    • @zoran-horvat
      @zoran-horvat  Год назад +14

      The greatest secret of software design is that every decision is a tradeof.

  • @Bankoru
    @Bankoru Год назад +6

    Essentially creating an algebra by adding an Identity element under the Add binary operator.

  • @cnaegle
    @cnaegle Год назад +1

    Great presentation from one of my favorite instructors! Making my development team watch it.

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

    Haven’t programmed in C# for a couple of years now, still loving the examples. Good job !

  • @robertmrobo8954
    @robertmrobo8954 Год назад +5

    Thank you for not using the default 'Order, product and Order Items' examples. 😊

  • @majixx
    @majixx Год назад +2

    Thank you again Zoran. Brilliant video!

  • @7th_CAV_Trooper
    @7th_CAV_Trooper 8 месяцев назад +1

    omg, a list of my favorite books.

  • @5cover
    @5cover Год назад +4

    IMO there's a flaw in your current implementation, as it is possible create a Money object with Currency.Empty and a non-zero amount.
    So it is possible to handle money without a currency.
    A possible solution is to throw an exception in the constructor if currency equals Currency.Empty.
    Also I would rename Currency.Empty to Currency.None, as there's no such thing as an "empty" currency.

  • @t304pk
    @t304pk Год назад +4

    Thank you for the impressive video, as always.

  • @tplummer217
    @tplummer217 Год назад +1

    Another excellent video sir!

  • @thygrrr
    @thygrrr 5 месяцев назад +1

    "There are obviously two kinds of money - Zero and Non-Zero"
    Me: "Wait... You guys have non-zero money?"

  • @10199able
    @10199able Год назад +8

    "poor man's polymorphism"

    • @zoran-horvat
      @zoran-horvat  Год назад +2

      Oh yes, you can find it everywhere.

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

      That makes you wonder which one is rich man polymorphism

    • @zoran-horvat
      @zoran-horvat  Год назад +5

      @@josebarria3233 Just polymorphism.

  • @thygrrr
    @thygrrr 5 месяцев назад +1

    8:30 "Money has just become abstract"
    ... not just...

  • @m4inline
    @m4inline Год назад +3

    Ming the Merciless retired as a coder?

  • @Skaral2
    @Skaral2 3 месяца назад

    How do you make the null object pattern work with Entity Framework? I had an entity with a navigation property to another entity ( Product 1:1 ProductPicture in separate tables), but it was possible for it to be NULL. I would like to replace the NULL with the null object, but I can't save it into the database since that'd create a duplicate.

    • @zoran-horvat
      @zoran-horvat  3 месяца назад +1

      @@Skaral2 EF Core does not support null objects out of the box. Custom mappings do not work because EF Care does not invoke it when the database field is null. Therefore, you cannot map a database null into a non-mull object in the application.
      There are at least two workarounds. One is to persist a private nullable field. The public getter would coalesce null into a null object. That is an easy solution, which avoids the complexities associated with persisting a hierarchy. The private field could be of the concrete type that acts as the non-mull case.
      A more engaged option is to have a null object persisted with a well-known ID value which is then also used in the application's null object instance. In that case, you can read and write objects as usual.
      There are a few details to work out in either case, but both options generally work well in practice.

  • @PedroPabloCalvoMorcillo
    @PedroPabloCalvoMorcillo Год назад +1

    Great ideas and insights. Not a big fan of throwing exceptions in this case, thought.

    • @zoran-horvat
      @zoran-horvat  Год назад +4

      There is a more complex design where Money separates "strict" addition from that with mixed currencies. However, subtraction can never be with mixed currencies, except for subtracting a zero...
      For a 100% safe and sound solution, we would need to return an Either monad from all strict methods. But with no syntactic support for errors in C#, the implementation and its use would become significantly more complex and less readable.

  • @malzsmith
    @malzsmith Год назад +1

    I'm loving your videos! Do you have plans to make content about async programming and synchronization?

    • @zoran-horvat
      @zoran-horvat  Год назад +1

      I have one video in the queue that talks about asynchronous programming, which I might record in the near future.

    • @malzsmith
      @malzsmith Год назад +1

      @@zoran-horvat glad to hear it, thank you!

  • @elraito
    @elraito 2 месяца назад +1

    "...lets add a touch of human. That is when we have no money" Look. It is illegal to make both excellent jokes and excellent video at the same time. Stop it.

  • @ŊŊŊ-d1q
    @ŊŊŊ-d1q 20 дней назад

    Lmao you invented a monoid

    • @zoran-horvat
      @zoran-horvat  20 дней назад

      @@ŊŊŊ-d1q You missed the point.