Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Abstract Factory using String paramater as Conctrete Class

18 views
Skip to first unread message

Sebastien Degardin

unread,
Mar 27, 2005, 8:48:53 AM3/27/05
to
Hello,

I need to use a Factory pattern to create services class.

i have an interface --> MyService
i can have an abstract class --> MyAbstractService
i have several concrete class for this service --> MyServiceVersion1_1
MyServiceVersion1_2.

I would like to create a factory which could instantiate object using
String (from XML file) as Class identifier. (maybe using a abstract
creator).

So that i'll be able to add some implementation class without rewritte
any lines on my code, only add concrete class to jar file and configure
XML file to use this.

example of a XML configuration file :

<IPNX>
<IPADDR>127.0.0.1</IPADDR>

<COMPSERVICE>
<VERSION>1.1</VERSION>
<IMPL-SERVICE-CLASS>
ict.wtl.ipnx.service.MyServiceVersion1_1
</IMPL-SERVICE-CLASS>
</COMPSERVICE>
</IPNX>

Thank's


--

-------------------
Sebastien Degardin
Intercall-Telecom
Java - J2EE (beginner)
sdeg...@powerdevNOSPAM.be

Raymond DeCampo

unread,
Mar 27, 2005, 12:57:35 PM3/27/05
to
Sebastien Degardin wrote:
> Hello,
>
> I need to use a Factory pattern to create services class.
>
> i have an interface --> MyService
> i can have an abstract class --> MyAbstractService
> i have several concrete class for this service --> MyServiceVersion1_1
> MyServiceVersion1_2.
>
> I would like to create a factory which could instantiate object using
> String (from XML file) as Class identifier. (maybe using a abstract
> creator).
>
> So that i'll be able to add some implementation class without rewritte
> any lines on my code, only add concrete class to jar file and configure
> XML file to use this.
>
> example of a XML configuration file :
>
> <IPNX>
> <IPADDR>127.0.0.1</IPADDR>
>
> <COMPSERVICE>
> <VERSION>1.1</VERSION>
> <IMPL-SERVICE-CLASS>
> ict.wtl.ipnx.service.MyServiceVersion1_1
> </IMPL-SERVICE-CLASS>
> </COMPSERVICE>
> </IPNX>
>
Was there a question in there?

Using my psychic powers, I'll guess that you need a pointer to look at
java.lang.Class.forName() and java.lang.Class.newInstance().

If you are interested in a pattern that does this that has been very
successful (integrates great with third party implementations), take a
look at java.sql.DriverManager.

Ray

--
XML is the programmer's duct tape.

Sebastien Degardin

unread,
Mar 27, 2005, 3:45:28 PM3/27/05
to

Yes, of course, i would like to get the concrete class from a XML file
dynamicaly at runtime.

To be able to add some implementation class easily in the future.

I'm gonna take a look at these class.

0 new messages