I'm stuck on a lightly philosophical question for me. I have three classes and I'm not sure how to make them related to each other. I have few competing approaches all of them standing on equal ground for me and I'm not sure which one has more cons and pros.
For example I'm designing system where I can command a device (and its subdevices) through Communicator:
- Device (e.g. Computer)
- Subdevice (e.g. Mouse, keyboard, screen)
- Communicator (e.g. network)
Device creates and holds onto Subdevice objects. And Device creates Communicator. Now let's say there is JSON comming into Communicator and it needs to be passed on to each of Device's Subdevice (ex parseJSON() method)
Do I:
- Create
Device::GetSubdevices()and for eachSubdevicecallparseJSONinsideCommunicatoror - Create
Device::onParsedJsoncalled byCommunicator, where I iterate and route toSubdevice - Do something else
First choice seems to bring Device's responsibility to Communicator which is not good. But second choice makes Device (+) handle routing responsibly (-) pollutes interface (even though it is interfaced)
parsingstep Devices and Subdevices are already created - so they will only update theirs state. JSON is not used application wide but it is not relevant. I'm undecided on a matter of path of JSON to subdevices. – edin-m Mar 01 '16 at 03:17