Help with Abstract Factory Pattern

Posted by brazc0re on Programmers See other posts from Programmers or by brazc0re
Published on 2012-06-08T16:57:14Z Indexed on 2012/06/08 22:47 UTC
Read the original article Hit count: 182

Filed under:

I need help with a abstract factory pattern design. This question is a continuation of: Design help with parallel process

I am really confused where I should be initializing all of the settings for each type of medium (ex: RS232, TCP/IP, etc).

Attached is the drawing on how I am setting up the pattern: enter image description here

As shown, when a medium is created, each medium imposes a ICreateMedium interface. I would assume that the Create() method also create the proper object, such as SerialPort serialPort = new SerialPort("COM1", baud); however, TCPIPMedium would have an issue with the interface because it wouldn't need to initialize a serial port object.

I know I am doing something majorly wrong here. I just can't figure it out and have been stuck for a while.

What I also get confused on show the interface IMedium will get access to the communication object once it is created so it can write out the appropriate byte[] packet.

Any guidance would be greatly appreciated. My main goal is to have the Communicator class spit a packet out without caring which type of medium is active.

© Programmers or respective owner

Related posts about design