Use Null Object Pattern in Your Rich Domain Model

  Рет қаралды 12,476

Zoran Horvat

Zoran Horvat

Күн бұрын

Пікірлер
@codingbloke
@codingbloke Жыл бұрын
Excellent presentation. Well balanced. None of the "Your doing X wrong!!" hysterics here.
@zoran-horvat
@zoran-horvat Жыл бұрын
The greatest secret of software design is that every decision is a tradeof.
@tarsala1995
@tarsala1995 Жыл бұрын
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 Жыл бұрын
Thank you for your comment. I am glad to hear the video was helpful.
@thygrrr
@thygrrr 7 ай бұрын
"There are obviously two kinds of money - Zero and Non-Zero" Me: "Wait... You guys have non-zero money?"
@cnaegle
@cnaegle Жыл бұрын
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 !
@thygrrr
@thygrrr 7 ай бұрын
8:30 "Money has just become abstract" ... not just...
@Bankoru
@Bankoru Жыл бұрын
Essentially creating an algebra by adding an Identity element under the Add binary operator.
@tplummer217
@tplummer217 Жыл бұрын
Another excellent video sir!
@majixx
@majixx Жыл бұрын
Thank you again Zoran. Brilliant video!
@t304pk
@t304pk Жыл бұрын
Thank you for the impressive video, as always.
@rmcgraw7943
@rmcgraw7943 Ай бұрын
I see you chose the singleton NoMoney class implementation, which is fine. I am curious if you considered making the NoMoney a readonly struct, or even readonly record struct? i can think of reasons to do it both ways, and reason why both ways might not be ideal in certain situations; howeverI was curious what your thoughts are regarding singleton class vs struct.
@zoran-horvat
@zoran-horvat Ай бұрын
@@rmcgraw7943 Structs cannot be used in the context of polymorphism other than through interface implementation, in which case you probably lose all performance gains of the struct allocation.
@robertmrobo8954
@robertmrobo8954 Жыл бұрын
Thank you for not using the default 'Order, product and Order Items' examples. 😊
@zoran-horvat
@zoran-horvat Жыл бұрын
Of course :)
@5cover
@5cover Жыл бұрын
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.
@zoran-horvat
@zoran-horvat Жыл бұрын
Good observations.
@10199able
@10199able Жыл бұрын
"poor man's polymorphism"
@zoran-horvat
@zoran-horvat Жыл бұрын
Oh yes, you can find it everywhere.
@josebarria3233
@josebarria3233 Жыл бұрын
That makes you wonder which one is rich man polymorphism
@zoran-horvat
@zoran-horvat Жыл бұрын
@@josebarria3233 Just polymorphism.
@7th_CAV_Trooper
@7th_CAV_Trooper 9 ай бұрын
omg, a list of my favorite books.
@Skaral2
@Skaral2 4 ай бұрын
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 4 ай бұрын
@@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.
@m4inline
@m4inline Жыл бұрын
Ming the Merciless retired as a coder?
@malzsmith
@malzsmith Жыл бұрын
I'm loving your videos! Do you have plans to make content about async programming and synchronization?
@zoran-horvat
@zoran-horvat Жыл бұрын
I have one video in the queue that talks about asynchronous programming, which I might record in the near future.
@malzsmith
@malzsmith Жыл бұрын
@@zoran-horvat glad to hear it, thank you!
@PedroPabloCalvoMorcillo
@PedroPabloCalvoMorcillo Жыл бұрын
Great ideas and insights. Not a big fan of throwing exceptions in this case, thought.
@zoran-horvat
@zoran-horvat Жыл бұрын
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.
@elraito
@elraito 4 ай бұрын
"...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 2 ай бұрын
Lmao you invented a monoid
@zoran-horvat
@zoran-horvat 2 ай бұрын
@@ŊŊŊ-d1q You missed the point.
Master the Power of Composite Pattern in Rich Domain Modeling
14:07
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
How To Self Host Behind CGNAT With Wireguard and pfsense
15:22
Lawrence Systems
Рет қаралды 9 М.
How to Avoid Null Reference Exceptions: Optional Objects in C#
18:13
Combine Design Patterns To Reveal Their Greatest Power
14:21
Zoran Horvat
Рет қаралды 8 М.
Tools EVERY Software Engineer Should Know
11:37
Tech With Tim
Рет қаралды 1,3 М.
This Is How the Anemic Domain Model Turns Bad
13:08
Zoran Horvat
Рет қаралды 10 М.