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:
Using a builder to construct complex classes
April 02, 2009 @ 12:58:28

If your code is getting more and more complex all the time and you find yourself creating a similar group of objects over and over, you might check out Jani Hartikainen's latest advice and create a "builder" around them.

Sometimes if you have a complex class, which needs to be set up in a specific way: Perhaps it takes a lot of constructor arguments, or often requires calling some setters. [...] Sometimes if you have a complex class, which needs to be set up in a specific way: Perhaps it takes a lot of constructor arguments, or often requires calling some setters.

His example is a "message builder" wrapper that lets you specify the receiver, sender and message and inject them into a to() method call (with a fluent interface). He shows how to make sure that the object you need (the message object) is always complete.

0 comments voice your opinion now!
fluent interface builder class complex tutorial


blog comments powered by Disqus

Similar Posts

Lorna Mitchell's Blog: 3 Ways to Access a Namespaced PHP Class

NetTuts.com: How to Use Selenium 2 With PHPUnit

Clear Code Blog: How to Manage Your Application Setup with Composer

Paul Jones' Blog: Brief Intro to Solar_Http_Request and Response

Artur Ejsmont's Blog: How to build mongodb pecl extension in 32bit for PHP 5.2 on OSX Snow Leaopard


Community Events





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


list community opinion api series symfony deployment laravel release conference library interview podcast tips threedevsandamaybe framework bugfix language zendserver introduction

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