views:

5

answers:

0

Hi,

I am working on an API with several classes/methods etc. Most of the methods return objects representing things like a CPU, DVD drive, etc.

We are implementing exception handling. Is it a good practise (not necessarily best...) to return an interface which all types (DVD drive, CPU, etc) derive from (this is good I know), but also derive another object (e.g. EmptyPCItem) to return if the method's return value is null? This means there are things like DVDDrivePCItem, CPUPCItem, and then EmptyPCItem.

The other (similar) approach is to return an object with a field like "PCItem" which can accept any type deriving from the interface, including the empty item. But checking this when consuming the method would be harder.

Which approach would be better?

Thanks