Content deleted Content added
m added wikilink to object-oriented programming section in Interface (computing) article |
|||
Line 22:
== Description ==
Instead of using a [[null reference]] to convey absence of an object (for instance, a non-existent customer), one uses an object which implements the expected [[Interface_(computing)#In_object-oriented_languages | interface]], but whose method body is empty. The advantage of this approach over a working default implementation is that a null object is very predictable and has no side effects: it does ''nothing''.
For example, a function may retrieve a list of files in a folder and perform some action on each. In the case of an empty folder, one response may be to throw an exception or return a null reference rather than a list. Thus, the code which expects a list must verify that it in fact has one before continuing, which can complicate the design.
|