Abstract Factory using String paramater as Conctrete Class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastien Degardin

    #1

    Abstract Factory using String paramater as Conctrete Class

    Hello,

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

    i have an interface --> MyService
    i can have an abstract class --> MyAbstractServi ce
    i have several concrete class for this service --> MyServiceVersio n1_1
    MyServiceVersio n1_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.se rvice.MyService Version1_1
    </IMPL-SERVICE-CLASS>
    </COMPSERVICE>
    </IPNX>



    Thank's


    --

    -------------------
    Sebastien Degardin
    Intercall-Telecom
    Java - J2EE (beginner)
    sdegardin@power devNOSPAM.be
  • Raymond DeCampo

    #2
    Re: Abstract Factory using String paramater as Conctrete Class

    Sebastien Degardin wrote:[color=blue]
    > Hello,
    >
    > I need to use a Factory pattern to create services class.
    >
    > i have an interface --> MyService
    > i can have an abstract class --> MyAbstractServi ce
    > i have several concrete class for this service --> MyServiceVersio n1_1
    > MyServiceVersio n1_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.se rvice.MyService Version1_1
    > </IMPL-SERVICE-CLASS>
    > </COMPSERVICE>
    > </IPNX>
    >[/color]
    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.Driver Manager.

    Ray

    --
    XML is the programmer's duct tape.

    Comment

    • Sebastien Degardin

      #3
      Re: Abstract Factory using String paramater as Conctrete Class

      Raymond DeCampo wrote:[color=blue]
      > Sebastien Degardin wrote:
      >[color=green]
      >> Hello,
      >>
      >> I need to use a Factory pattern to create services class.
      >>
      >> i have an interface --> MyService
      >> i can have an abstract class --> MyAbstractServi ce
      >> i have several concrete class for this service --> MyServiceVersio n1_1
      >> MyServiceVersio n1_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.se rvice.MyService Version1_1
      >> </IMPL-SERVICE-CLASS>
      >> </COMPSERVICE>
      >> </IPNX>
      >>[/color]
      > 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.Driver Manager.
      >
      > Ray
      >[/color]

      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.

      Thank's

      --

      -------------------
      Sebastien Degardin
      Intercall-Telecom
      Java - J2EE (beginner)
      sdegardin@power devNOSPAM.be

      Comment

      Working...