anyone want to give some OOD advice?

Hi all -

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.

Thanks for any help you might provide.
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.
1
2
3
4
5
6
7
class Message{
    //...
public:
    //...
    void set_device_info(const DeviceInfo &);
    //...
};
?
Is it a problem for Message to know about DeviceInfos?
closed account (48T7M4Gy)
Pseudocode of possible classes/objects:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Device
{
    private string configuration
    
    public methods: 
        void send_message(Message m);
        Message receive_message();
        void set_configuration(); or void set_configuration(Message m);
};

class Message
{
    private string contents

    public methods:
        void set_contents(string str);
        string display_contents();
};
Thanks for the input, guys. I did indeed mean "hash table" above, and I like helios' suggestion of just passing along the object. That seems to work well.

When I said "handles" messages, I meant formatting them and the like. The actual IO is done in another class.
Registered users can post here. Sign in or register to post.