You are here: Re: instantiating an object fails (design patterns) « PHP Programming Language « IT news, forums, messages
Re: instantiating an object fails (design patterns)

Posted by Oli Filth on 09/16/05 20:32

Marcin Dobrucki said the following on 16/09/2005 13:37:
> www.douglassdavis.com wrote:
>
>> lets say i have a class class Thing
>> {
>> function __construct($string)
>> {
>> // initialize by string
>> }
>> }
>
> ...
>
>> What would be appropriate here?
>
>
> I am not sure about appropriate, but you could try something like this:
>
> class Foo {
> function Foo($id) {
> $this->setId($id);
> $this->initialize();
> }
>
> function initialize() {
> ...
> }
> }
>
> I usually do it so that inside the constructor, I do things that are
> very unlikely to fail (eg. set constants, etc), and then defer stuff
> that can fail (eg. getting stuff from DB, etc), to the initalizing
> function.
>

What? How does that help?
If initialize() "fails" then the constructor has still "failed"...

--
Oli

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация