News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jani Hartikainen's Blog:
What is a null object, and when are they useful?
September 14, 2009 @ 12:46:10

In this latest post to his blog Jani Hartikainen looks at creating "null objects" for your applications - a simple tool that lets you replace multiple evaluation checks with a simple object.

How many times have you written code, which checks if a value is null, and then displays something special because of that? Have you written the very same check in more than one place in your code? A null object is an elegant solution to this.

His example shows how to replace a standard User class to grab the user's name with an anonymous user that extends it to return the string "Anonymous User" instead. By creating an intermediate class like this, you can simple call a "getName" and know that there will be some sort of value as the result.

0 comments voice your opinion now!
null object anonymous tutorial


blog comments powered by Disqus

Similar Posts

PHP-GTK Community Site: GtkToolbar, GtkMenubar, and PEAR XML-RPC for geo-nick

ProDevTips.com: PHP Doctrine - adding automatic, simple CRUD

Spindrop.us: Digg-style AJAX comment editing in PHP/symfony

Zend Developer Zone: ZendCon Wrapup

Derick Rethans' Blog: Remote Debugging PHP with a Firewall in the Way


Community Events

Don't see your event here?
Let us know!


framework series podcast symfony2 language interview php7 introduction example library application opinion release conference performance laravel configure community api voicesoftheelephpant

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework