Null Object

Null ObjectShort Description
Null Object. Something for Nothing. Kevlin Henney. March 2003. kevlin@curbralan.com. kevlin@acm.org. Abstract. The intent of a N …

Website: www.two-sdg.demon.co.uk | Filesize: 210kb

Content
Null Object
Something for Nothing
Kevlin Henney
March 2003
kevlin@curbralan.com
kevlin@acm.org
Abstract
The intent of a NULL OBJECT is to encapsulate the absence of an object by providing a
substitutable alternative that offers suitable default do nothing behavior. In short, a design
where “nothing will come of nothing” [Shakespeare1605].
NULL OBJECT is a tactical pattern that has been discovered time and again, and not only in
object-oriented systems: null file devices (/dev/null on Unix and NUL on Microsoft systems),
no-op machine instructions, terminators on Ethernet cables, etc.
The pattern has been documented in a variety of forms by many authors, varying widely in
structure and length: from a thorough and structured GOF-like form [Woolf1998] to a brief
thumbnail-like production-rule form [Henney1997]. This paper is derived from a
previously published article [Henney1999] and includes the aforementioned thumbnail.
The aim of the current work is to update and capture the latest understanding of the
pattern and its implications, also addressing a wide audience by documenting the pattern
primarily with respect to Java and UML.Null Object
2 of 10
Thumbnail
if
.. An object reference may be optionally null and
.. This reference must be checked before every use and
.. The result of a null check is to do nothing or assign a suitable default value
then
.. Provide a class derived from the object reference’s type and
.. Implement all its methods to do nothing or provide default results and
.. Use an instance of this class whenever the object reference would have been null
Problem
Given that an object reference may be optionally null, and that the result of a null check is
to do nothing or use some default value, how can the absence of an object - the presence
of a null reference - be treated transparently?
Example
Consider a logging facility for some kind of simple server-housed service. It can be used to
record exceptional events, housekeeping activities, and the outcome of operations during
the course of the service’s operation. One can imagine many different kinds of log, such as
a log that writes directly to the console or one that uses RMI to send a message to a remote
logging server. However, a server is not…

Get the file Download here

AddThis Social Bookmark Button
Related Books:
  • A brief MySQL tutorial
  • XML to Object Binding Tutorial
  • Object-Oriented Programming
  • Illustrator Training 2006.indd
  • Object-Oriented Programming With ANSI-C
  • SECURITY of WINDOWS 2000 SERVER SECURITY of WINDOWS 2000 SERVER …
  • Abstract classes, 17, 80 Actors (UML), 51 Adapter design pattern …
  • Nokia M2M Platform Server Application Programming Guide

  • Related Searches:



    Comments

    Leave a Reply