Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 2
    Nice. I like the thought "To keep things simple I wouldn't allow the Client property of any Room instance to ever be null. " That is indeed better than to question what to do when it is null Commented Aug 24, 2015 at 13:40
  • @Michel if you later decide to change that requirement, you can replace the null value with a NullObject (or rather NullClient) which would then still work with your existing code and allow you to define behaviour for a non existent client if need be. The question is if the "no client" case is part of the business logic or not. Commented Aug 24, 2015 at 13:58
  • 3
    Totally correct. Don't write a single character of code to support an unsupported state. Just let it throw a NullRef. Commented Aug 24, 2015 at 19:16
  • @Ben Disagree; MS guidelines explicitly state that property getters should not throw exceptions. And allowing null refs to be thrown when a more meaningful exception could be thrown instead is just lazy. Commented Aug 25, 2015 at 12:57
  • 1
    @Andy understanding the reason for the guideline will allow you to know when it doesn't apply. Commented Aug 26, 2015 at 22:36