Modelling problem - Networked devices with commands

Posted by Schneider on Stack Overflow See other posts from Stack Overflow or by Schneider
Published on 2010-03-11T13:10:18Z Indexed on 2010/03/11 21:39 UTC
Read the original article Hit count: 309

Filed under:
|
|

I encountered a head scratching modelling problem today:

We are modelling a physical control system composed of Devices and NetworkDevices. Any example of a Device is a TV. An example of a NetworkDevice is an IR transceiver with Ethernet connection.

As you can see, to be able to control the TV over the internet we must connect the Device to the NetworkDevice. There is a one to many relationship between Device and NetworkDevice i.e. TV only has one NetworkDevice (the IR transceiver), but the IR transceiver may control many Devices (e.g. many TVs).

So far no problem.

The complicated bit is that every Device has a collection of Commands. The type of the Command (e.g IrCommand, SerialCommand - N.B. not currently modelled) depends on the type of NetworkDevice that the Device is connected to.

In the current legacy system the Device has a collection of generic Commands (no typing) where fields are "interpreted" depending on the NetworkDevice type.

How do I go about modelling this in OOP such that:

  • You can only ever add a Command of the appropriate type, given the NetworkDevice the Device is attached to?
  • If I change the NetworkDevice the Commands collection changes to the appropriate type
  • Make it so the API is simple/elegant/intuitive to use

© Stack Overflow or respective owner

Related posts about modelling

Related posts about oop