tag:blogger.com,1999:blog-3237724005744642470.post6057968545425138327..comments2014-05-08T19:21:43.321+01:00Comments on Captain Debug's Blog: Null Return Values and the Special Case PatternRoger Hugheshttp://www.blogger.com/profile/07042290171112551665[email protected]Blogger2125tag:blogger.com,1999:blog-3237724005744642470.post-52229300689587300912011-06-24T16:47:26.562+01:002011-06-24T16:47:26.562+01:00Thanks for getting in touch. The motivation for th...Thanks for getting in touch. The motivation for the Special Case Pattern is to make your code less brittle by avoiding NullPointerExceptions<br /><br />In this example, if you don’t use the Special Case Pattern and the Employee does not have a phone, then the empty phone number attribute of the employee's record is null. Any client code that uses the phone number of the Employee class must either constantly check for a null value, or suffer a NullPointerException when the phone number is empty.<br /><br />If you define an empty field as an empty string and not a null reference, then your client’s code won’t need to check for null and won’t crash. Furthermore, if the Employee class is used by 20 client’s, then by effectively moving the null check to inside the Employee, each of the 20 client’s don’t have to check for null saving a lot of time and effort.<br /><br />Hope this answers your question.Roger Hugheshttp://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-73751505252058528772011-06-24T14:44:02.011+01:002011-06-24T14:44:02.011+01:00Hi,
I have gone through your blogs and understood ...Hi,<br />I have gone through your blogs and understood usage of Special Case Pattern. However I have doubt, what if I need to do something with the phone number of the Employee, and that is needed by another class. Now instead of null I will get an empty String. I am confused. Please explain More.<br /><br />Thanks and Regards,<br />Saravanan.KAnonymous[email protected]