If you make DeviceType
an enum
, then you only need to check for null. If Device
s require a type, the time to check that is when Device
gets constructed. In the unlikely event that type is an optional property for a Device
, you can either (a) claim that untyped devices do not match the requiredType, and so you don't return them, or (b) check as you go through and handle the failure. If you do (b), you should only use an assertion if this method is internal-facing (private). If it's public, you need to throw an exception, either runtime or checked.
It is reasonable and expected for documentation to list preconditions.