Use Null Object Pattern in Your Rich Domain Model

2023 ж. 25 Мам.
9 814 Рет қаралды

The source code from this demo is available on Patreon: / use-null-object-83554737
Ever wondered about the impact of the Null Object design pattern on domain modeling? This video offers a deep dive into this fascinating topic, demonstrating how identifying objects that behave like 'zero' can create a more intuitive and friendly model, even in a complex business domain.
We bring this concept to life through a real-world example, demonstrating the significant influence of 'null objects' in a deep domain model when it comes to implementing essential features. Watch this video to experience this simplifying effect firsthand!
And not just that, we also reveal situations where you might want to avoid using the Null Object pattern by adding a touch of complexity to your classes, but gaining more from their simple and intuitive public interface. Discover why maintaining a simple public interface could be advantageous over polymorphic Null Object implementation.
By the end of this journey, you'll be equipped with the know-how to apply these concepts creatively in your domain modeling, ultimately leading to more structured code.
Thank you so much for watching! Please like, comment & share this video as it helps me a ton!! Don't forget to subscribe to my channel for more amazing videos and make sure to hit the bell icon to never miss any updates.🔥❤️
✅🔔 Become a patron ► / zoranhorvat
✅🔔 Subscribe ► / @zoran-horvat
⭐ Learn more from video courses:
Beginning Object-oriented Programming with C# ► codinghelmet.com/go/beginning...
⭐ Collections and Generics in C# ► codinghelmet.com/go/collectio...
⭐ Making Your C# Code More Object-oriented ► codinghelmet.com/go/making-yo...
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⭐ CONNECT WITH ME 📱👨
🌐Become a patron ► / zoranhorvat
🌐Buy me a Coffee ► ko-fi.com/zoranhorvat
🗳 Pluralsight Courses ► codinghelmet.com/go/pluralsight
📸 Udemy Courses ► codinghelmet.com/go/udemy
📸 Join me on Twitter ► / zoranh75
🌐 Read my Articles ► codinghelmet.com/articles
📸 Join me on LinkedIn ► / zoran-horvat
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
👨 About Me 👨
Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my KZhead channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️RIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorised to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
⭐For copyright or any inquiries, please contact us at zh@codinghelmet.com
#dotnet #csharp #designpatterns

Пікірлер
  • Excellent presentation. Well balanced. None of the "Your doing X wrong!!" hysterics here.

    @codingbloke@codingbloke Жыл бұрын
    • The greatest secret of software design is that every decision is a tradeof.

      @zoran-horvat@zoran-horvat Жыл бұрын
  • I rarely watch videos twice. This one opened my eyes. I think your videos are reminding us how we should look at the code.

    @tarsala1995@tarsala1995 Жыл бұрын
    • Thank you for your comment. I am glad to hear the video was helpful.

      @zoran-horvat@zoran-horvat Жыл бұрын
  • Essentially creating an algebra by adding an Identity element under the Add binary operator.

    @Bankoru@Bankoru Жыл бұрын
  • Great presentation from one of my favorite instructors! Making my development team watch it.

    @cnaegle@cnaegle9 ай бұрын
  • Haven’t programmed in C# for a couple of years now, still loving the examples. Good job !

    @driden1987@driden198710 ай бұрын
  • omg, a list of my favorite books.

    @7th_CAV_Trooper@7th_CAV_Trooper2 ай бұрын
  • Thank you again Zoran. Brilliant video!

    @majixx@majixx Жыл бұрын
  • Thank you for not using the default 'Order, product and Order Items' examples. 😊

    @robertmrobo8954@robertmrobo8954 Жыл бұрын
    • Of course :)

      @zoran-horvat@zoran-horvat Жыл бұрын
  • Thank you for the impressive video, as always.

    @t304pk@t304pk Жыл бұрын
  • Another excellent video sir!

    @tplummer217@tplummer2178 ай бұрын
  • "poor man's polymorphism"

    @10199able@10199able Жыл бұрын
    • Oh yes, you can find it everywhere.

      @zoran-horvat@zoran-horvat Жыл бұрын
    • That makes you wonder which one is rich man polymorphism

      @josebarria3233@josebarria3233 Жыл бұрын
    • @@josebarria3233 Just polymorphism.

      @zoran-horvat@zoran-horvat Жыл бұрын
    • ​@@josebarria3233 Probably a refinement type, so you can specify a nominal base type, but then a refined subtype is one that meets some condition like `amount == 0`. That way you could group the changes in the behavior of each subtype.

      @dispatch-indirect9206@dispatch-indirect9206 Жыл бұрын
  • Ming the Merciless retired as a coder?

    @m4inline@m4inline Жыл бұрын
  • I'm loving your videos! Do you have plans to make content about async programming and synchronization?

    @malzsmith@malzsmith11 ай бұрын
    • I have one video in the queue that talks about asynchronous programming, which I might record in the near future.

      @zoran-horvat@zoran-horvat11 ай бұрын
    • @@zoran-horvat glad to hear it, thank you!

      @malzsmith@malzsmith11 ай бұрын
  • 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.

    @5cover@5cover Жыл бұрын
    • Good observations.

      @zoran-horvat@zoran-horvat Жыл бұрын
  • Great ideas and insights. Not a big fan of throwing exceptions in this case, thought.

    @PedroPabloCalvoMorcillo@PedroPabloCalvoMorcillo Жыл бұрын
    • 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.

      @zoran-horvat@zoran-horvat Жыл бұрын
  • This is really interesting because calling it the "null" pattern shows how null conflates two related ideas; that of zero and bottom. There are really two patterns: the zero object pattern and the bottom type pattern. And, in most languages, you use a "bottom object" to work around the lack of support for a proper bottom type. The number 0 is a regular number, it's only special in how arithmetic works. It is a zero object in itself, since it checks all the boxes of a regular number. A bottom type, though, is the type with no values, sometimes called void or nothing. (As many people find it hard to accept that 1/0 doesn't have a value, we also intuitively want to have a bottom value, which I think is where null and undefined come from.) Here, Currency.Empty is properly the _absence_ of a currency. But C# doesn't really let you indicate the absence of a value, so you're (reasonably) using the bottom object pattern. Notably, it doesn't check all the boxes of a currency; especially, you can only have 0 of it. And the relation between zero and bottom is that you use Currency.Empty to create Money(0, Currency.Empty); the bottom type is often an element of a zero value. Another example: if you have immutable (and thus covariant) lists, the element type for the empty list would be Bottom. Since Bottom is a subtype of all types, List concat List gives you a List, as X is the common supertype of X and Bottom. And, a List is always the empty list (the zero value for List) since you can never get a value of type Bottom.

    @dispatch-indirect9206@dispatch-indirect9206 Жыл бұрын
    • Very nice explanation, thank you.

      @zoran-horvat@zoran-horvat Жыл бұрын
KZhead