Reply to Re: factory pattern in php

Your name:

Reply:


Posted by Michael G on 11/15/67 11:22

"Michael G" <mike-g@montana.com> wrote in message
news:42e66b59$1_2@spool9-west.superfeed.net...
>I want to use a factory pattern to create a variety of objects. Which
>object gets created depends on a string that is passed to the factory
>create method. I would like to avoid using an if or switch construct to
>accomplish this but not sure how. For example,
>
> ...
>
> if($nextObject == "login")
> {
> return new Login();
> }
> else if($nextObject == "validatedata")
> {
> return new Validate(aString);
> }
>
> ...
> Is there any way to avoid this?
>


Actually there is a way to do this but I am sure how appropriate it is.
Here is a simple of example of the concept. It does what I want but not
convinced this is the best way to do it. If it is then I could simply place
a list of strings in an array and index them with an input string.

<?php

class A
{
function A()
{
print("creating A");
}

}


$a = "A";
new $a."()";

?>

Thanks mike



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

[Back to original 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

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