Home Help Center

Question about ObjectFactory

Hi :
I would like to ask, what is the function of ObjectFactory?

In the Ice Jave demo Example,
In the Client :
PrinterHolder printer = new PrinterHolder();
PrinterPrxHolder printerProxy = new PrinterPrxHolder();

..............

Ice.ObjectFactory factory = new ObjectFactory();
communicator().addObjectFactory(factory, "::Demo::Printer");

initial.getPrinter(printer, printerProxy);
System.out.println("==> " + printer.value.message);
What is the different between that I just new a Printer Object(PrinterI printer = new PrinterI();) in the Client instead of using ObjectFactory to get the Object? As I know that ther Printer Object in the PrinterHolder is a new Object. Thanks:D

Comments

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    The object factory is used by the ice runtime to create objects when it receives them by value over the wire. Consider:
    class Foo
    {
       void dosomething();
    };
    
    interface FooFactory
    {
       Foo create();
    };
    

    Note that create returns a Foo object, not a Foo proxy. When FooFactory.create is called without the object factory the ice runtime would have no way to determine what implementation object to create for Foo on the receiving side.
  • kongchoykongchoy Member
    Thanks! I got your point.

    But I would like to ask more about the ObjectFactory.
    If I use the Ice Output streaming to write in an Object, and use the Helper(inputstream, Holder) function to get this object in the Holder, Should I need to add the ObjectFactory first????
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Writing does not need the object factory, only reading. If you read you always need to add an object factory -- unless the type is non-abstract -- that is it has no methods. In this case the slice generated class is instantiated (provided that you have no provided an object factory for this type). I suggest reading the Ice manual for more information.
  • kongchoykongchoy Member
    Thanks

    Thank you very much!!!!!!:)
Sign In or Register to comment.