I've been programming in C++ for a few years, but I'm still relatively new to the OOD aspect of programming. I'm currently writing a small application in C++, and early on, I'm thinking that I need some help.
The app communicates with an embedded device through a serial port. I'm using the Qt platform, so my two primary Classes are a Widget (for display) and a Worker (for everything else). Classes under the Worker include:
- Serial: handles the communication with the device
- Message: handles messages to/from the device. Includes all the formatting, encryption/decryption, authentication etc.
- Device: all the information about the remote device: serial number, MAC address and a host of other fields.
Currently, my Worker object "wakes up" upon getting a message from the remote device. It parses it, and based on the message type, constructs a response and sends it out.
The reason I think I may be doing something wrong is that I'm stuck for a convenient way to pass the device information to the message object. I have the information in the worker object in a hash; is it sound programming to pass the hash to the message object?
The real issue is whether I've properly broken out the objects. I'd greatly appreciate some input on this.
Your naming is kind of misleading. A Message should be something you send, not something that you use to send things. It would be like saying that a phone is a conversation. Your Message class should be renamed to Protocol or Pipe or something.
That aside, I'm not sure I understand what you mean here:
I have the information in the worker object in a hash; is it sound programming to pass the hash to the message object?
Do you mean a hash, or a hash table? I don't know what it means to "have things in a hash", but I also don't know why you'd pass a hash table when you want to pass a single object.
Now, you say you want your Worker to pass some data to your Message. Is there any reason why you can't just pass a pointer to that data, or a copy of that data? I don't really understand what the problem is.