locked
Design consulting RRS feed

  • General discussion

  • Hi all,

    I have the following design conflict :

    I have to write an application that reads and writes values to hardware device.

    I have two filed devices maybe more in the future (D1,D2,...)

    Each device has it's way for making communication.

    I thought to make the design as following :

    1. Build IDevice interface

    2. Build D1 class and D2 class that implement IDevice.

    3. Build Tag class that maintain the value of certain adress in the devices.

    4. Build a serial port class that implements the communication with the COM ports.

    I want to build a container of Tag class witch may relate to D1 class or D2 class.

    I don't know how to connect between the Tag class and the D1,D2. I thought to put a reference to D1 in Tag but maybe the Tag related to D2 so I need also instance to D2.

    What is the correct way to do that.

    Thanks in advance.

    Regards...

     

     

     

     

     

     

    Wednesday, November 15, 2006 3:45 PM

All replies

  • A manager pattern comes to mind. You would have a devicemanager class that holds the devices. You could then have a refernce to this class from the Tag class (or an interface implemented by the devicemanager). The devicemanager should then have a way to retrieve one of the devices. It's up to you, to make a distinction between the devices, as I don't know enough about the actual application to see this.

    Tuesday, December 5, 2006 11:55 AM
  • Here's my take: I'd start with steps 1 and 4.  Step 1 should be fairly easy if you're doing your design work up front (which it sounds like you are).  Step 4 is hardware-level stuff that should be "abstracted out" of the design process as soon as possible.  Get it up and running and provide a sensible interface through which it can exchange data with the rest of your code, and you shouldn't need to worry about it again.

    From what you're saying, Tag shouldn't have references to anything else.  D1 and D2 objects may contain hashtables or collections of Tag objects, but nothing in Tag should be tied to other program components.

    Tuesday, December 5, 2006 3:39 PM
  • I am not sure if I completely understand your scenario. Maybe you are just needing  to hold an IDevice in the tag class (which enables you to store either D1 or D2). The device manager mentioned eirlier, will enable you to get the corresponding D1 or D2 without directly referencing them.

    Tuesday, December 5, 2006 6:46 PM
  • if I understand what you want correctly

    you can have your Tag class accept an IDevice in its constructor (or a setter) and inject the correct device sub-class when you instantiate a Tag class

    Arnon

    Sunday, December 10, 2006 9:35 PM