Talk:Null object pattern
This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||
|
First Description
[edit]The article originally claimed the pattern "...was first published in the Pattern Languages of Program Design book series.[1][year needed]". The year associated to the referenced publication is 1998. There is an earlier paper from Nov. 1997 "[The Null Object Pattern]" by Woolf. An even earlier publication is "[Nil and None considered Null and Void]" published in 1996 (WOON'96, St. Petersburg, Russia). The latter publication uses "Void Value" as the pattern name, but the pattern described is equivalent to "Null Object". ClassA42 (talk) 02:18, 21 April 2022 (UTC)
This article is - like others have commented - not of high quality. The pattern has loads of better descriptions online. Howerver, the advantage statement is confusing and does not - IMO - speak of the key purpose (see the references from the article). I left it there, but I added a key purpose statement. Chipbite-mawi (talk) 09:00, 13 September 2023 (UTC)
Strange "contradictory" intro statements for examples
[edit]- the C++ example "illustrates how the pattern is more complicated with types"
- the C# example shows how it can be properly implemented (this properly implemented seems to imply the example before is not proper, it however is almost identical).
Kasterma (talk) 17:48, 2 October 2014 (UTC)
Missing example: Qt
[edit]This article should mention the Qt framework. AFAIK, It is the only widely-used C++ library that implements null objects consequently. Ever wondered why the Qt framework uses neither exceptions nor C-style error codes? It is solely because of proper use of Null objects. Vog (talk) 16:23, 4 June 2014 (UTC)
Disagree with the article's statement
[edit]This article is completely wrong. Null pointers and Null variables have little or nothing to do with the Null Object design pattern. http://www.cs.oberlin.edu/~jwalker/nullObjPattern/
- Maybe I phrased things badly - my understanding is that one reason for the pattern is to avoid the checking needed to make sure a variable doesn't have a Null pointer or value as these add to the complexity of code, making it harder to maintain. If I'm mistaken, I'd gladly like to learn better. Autarch 12:23, 28 September 2007 (UTC)
- Upon reading the article, I thought that you were saying that we were using 'null' varaibles and checking whether they were 'null' each time we used them. If I understand correctly, the Null Object Pattern is actually about an object which implements default behavior in absence of something else. For instance, an implementation of an interface whose methods bodies are empty. The article is bad, but strangely it has excellent external links to flesh out a fair article. Ruijoel 13:06, 25 October 2007 (UTC)
- Apologies for badly phrasing things in the article - I'd got information from secondary sources - any flaws are my fault, not theirs. Autarch (talk) 16:12, 14 January 2008 (UTC)
- Upon reading the article, I thought that you were saying that we were using 'null' varaibles and checking whether they were 'null' each time we used them. If I understand correctly, the Null Object Pattern is actually about an object which implements default behavior in absence of something else. For instance, an implementation of an interface whose methods bodies are empty. The article is bad, but strangely it has excellent external links to flesh out a fair article. Ruijoel 13:06, 25 October 2007 (UTC)
I think a better example is that of a logger. Often you see code if logger != null then logger.log ( message ). With the null object pattern you then have a NullLogger which just ignores the input and you get logger.log ( message ). Also, often these null subclasses are singletons (since ignoring everything is often stateless). CaptainPinko (talk) 19:29, 10 May 2010 (UTC)
It looks like the article has been updated, as the content is correct now. The examples are still bad, though. The C example misses the concept entirely (the pattern requires the concept of objects, so I don't know that this pattern can be implemented in C) and while an empty C# array may exhibit similar behavior to a null object, it certainly isn't a good example of the practical use of the pattern. Bgano (talk) 22:35, 18 April 2011 (UTC)
Criticism of Criticisms
[edit]I have not read "Fowler, Martin (1999). Refactoring pp. 261", but the "Critisism" section is very weak and lacking of any actual criticisms. There is no value in saying "this may cause bugs, as references this source". 202.65.14.164 (talk) 22:05, 12 March 2013 (UTC)
function tree_size(null_node) { return 0 }
[edit]Can someone direct me to programming languages where exactly this or a very similar implementation is possible?
Thanks. — Preceding unsigned comment added by Brusinsky (talk • contribs) 12:55, 14 May 2016 (UTC)
How would the right method be called?
[edit]function tree_size(node) {
return 1 + tree_size(node.left) + tree_size(node.right)
}
function tree_size(null_node) {
return 0
}
This separates normal logic from special case handling and makes the code easier to understand. 76.33.14.118 (talk) 00:08, 26 October 2024 (UTC)