lets say we have a class called Intersection, with a findIntersect(line1, line2) method. It returns an object called point, with 2 fields the x and y coordinates. Now, if the input are 2 parallel lines, what is the best way to communicate that no result was obtained with the user? Though example is specific to lines, the question is generic - assuming a method returns value object, what to return if conditions don't match? Some options are:
- Return
null(issue: read in many places that null return value should be avoided if possible) - Have a method in object which determines if object is valid, similar to
hasNext()inIterator? - Throw an
Exception?
Please let me know best approach.