Separate Objects and Separate State
Use separate objects to avoid null.
We'll cover the following...
We'll cover the following...
So far, we have used language features to avoid null and a possible NullReferenceException, like null checks and nullable operators and references. Let’s see how to better design our objects to avoid null when representing optional values.
Avoiding null and a possible NullReferenceException
Often, we keep all possible combinations of properties of an object in a single class.
For an e-commerce site, we create a User class with different properties: name, password, and CreditCard. But we don’t need credit card details during a trial period, for ...