[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Factory Method



On Fri, 21 Mar 2003 09:10:29 -0800 (PST), Kevin O'Neill Stoll
was overheard saying:
|  My question is, how do I convert a querystring parameter
|  that identifies the type of search to invoke into an object
|  in which a factory method function could use?

Kevin,

You can do this by using the Class.forName(String) method, which
allows you to give the fully qualified class name as a String and
retrieve the Class object that matches (if found).  Once you have the
Class object you can then use the Class.newInstance() method to create
a new instance of that class (with the no argument constructor).  You
can then cast the resulting Object down to whatever sort of SearchBean
that it really is and continue normally.

Many developers elect to employ the Factory design pattern to solve
this challenge.

http://gsraj.tripod.com/design/creational/factory/factory.html
http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/FactoryPattern.htm
http://patterndigest.com/patterns/AbstractFactory.html

-R

-- 
Robert Gash, gashalot@gashalot.com
(Web) http://gashalot.com/
(PGP) http://gashalot.com/pgpkeys.txt