Home Help Center

object factories in slice

Hello all,
I've found in the overview web pages an interesting way to play with objects factories
----
interface Invoice {
void addItems(ItemSeq items);
void submit();
};
interface InvoiceFactory {
Invoice* create();
};
----

that makes the usage of factories very simple (this is the python sample)
----
# Create a proxy for the invoice factory object.
proxy = communicator.stringToProxy("InvoiceFactory:tcp -p 9000")

# Narrow the proxy to the proper type.
factory = Biz.InvoiceFactoryPrx.checkedCast(proxy)

# Use the factory to obtain a proxy for a new invoice object.
invoice = factory.create()
----

Unfortunately, I'm not able to find in the documentation and in the samples other usages of this technique: is it possible to have more details (perhaps a working server implementation) ?

Thanks in advance
/gp

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    For an example that also involves the use of Freeze, have a look at demo/Freeze/phonebook or demo/Freeze/library. Another example is demo/IcePack/hello, which also demonstrates the use of IcePack.
  • japanmanjapanman Member
    Thanks for your quick reply,
    I've borrowed from demo/IcePack/hello: here's my minimalist InvoiceFactoryI python implementation
    class InvoiceFactoryI(Biz.InvoiceFactory):
    
        def create(self, current=None):
            adapter = current.adapter    
            obj = adapter.addWithUUID(InvoiceI())   
            return Biz.InvoicePrx.uncheckedCast(obj)
    

    And it seems to work.
    Thank you very much.
    /gp
Sign In or Register to comment.