Object factory??

From: Hullaballoo (w_at_w.w)
Date: 06/30/04

  • Next message: Andreas Rossberg: "Re: SoA Vs OO"
    Date: Wed, 30 Jun 2004 13:20:35 GMT
    
    

    We have a couple of unrelated network protocols that we're wrapping in C#. I
    have found myself doing a similar thing in each wrapper.

    Basically, the incoming bytes or xml (or whatever) is used to construct an
    object, but I don't know what type of object I'm creating when the data
    comes in.

    The actual packet type is stored in the incoming data. What our original
    software did was to peek at the packet type, then have a big switch
    statement constructing the correct concrete type.

    I changed this and had a custom attribute on each class that could be
    constructed from the incoming data, the attribute declaring which packet
    type the class could be instantiated from. After the factory peeks at the
    packet types, it simply reflects on all class and chooses the one to
    instantiate. This obviously obeys the OCP and is an OK solution.

    I can't help feeling that this sort of thing must have been done a thousand
    times before and there might be a better way.

    Any suggestions??

    Ta


  • Next message: Andreas Rossberg: "Re: SoA Vs OO"