I work on a product that has many components, most of them are written in C ++ Is written in We are often the scenario where a part of the information flows through each component through the IPC.
We define these messages using strokes so that we can pack them in messages and send them to the message queue. These strokes are designed for 'transport' purposes only and are written in a similar manner that only works for that purpose. The problem I am facing is that the programmers are holding on to the structure and the information For this, use it as a long-term container.
This is a problem in my eyes because:
1) If we change the transport infrastructure, then all their code breaks. There should be encapsulation here so that we do not go into this scenario.
2) Message stranks are very weird and only the information is designed to transport ... It seems that this structure is the most used to access this data (long duration) for these other components. There may also be a convenient form.
My question is: How can I prevent the program from being misused? I want to implement that these structures can be used only for transportation.
Edit: I will try to provide an example here, which I can do best:
straight short element {int id; Int basicFoo; }; Structure Medium Element {int id; Int basicBar; Int numSmallElements; Structure Small Element Small Elements [MAX_NUM_SMALL]; }; Struct largeElement {int id; Int Basic Buzz; Int Nambamidium Elements; Structure Medium Element [MAX_NUM_MEDIUM]; }; The effect is that people, instead of extracting the data obtained from those large elements, have to keep a 'bigger' element and keep them in the sections which are required by their needs. Complete.
When I define message structures (in C ++, not valid in C)
Message object is copiable Message object only to be created once Message object Can not be changed after creation I'm not sure the message will still be fade, but I think this memory point is equivalent to the view.
Become a member Become a member > For example, you may have:
structure message {int id; Long data; Information information; }; Then you have to:
Class message // Straight or whatever, just make sure public / private are set correctly {Public: Message (int id, long data, long info): m_id (id), m_data (data), m_info (info) {} int id () const {return m_id; } Long data () const {returns m_data; } Info information () const {return m_info; } Private: int m_id; Long M_data; Information m_info; }; Now, users will be able to create messages, to read from, but can not change it for a long time, so that it becomes unusable as a data container. Although they can handle a message but will not be able to change it later, therefore it is only useful for memory.
Or .... You can use "black box" . - Separate the message layer in the library, if not already.
- The client code should not be displayed in message configuration definitions at all, so do not provide the header, or hide them or something.
- Now, provide the function to send the message, which will create (inside) messages and send them. It will also help in reading the code.
- When receiving the message, provide a way to notify the client code. But do not directly message !!! Just keep them somewhere (perhaps using temporary or lifelong rules or something) in your library, perhaps in some kind of manager, but keep them in the black box. Simply provide one type of message identifier.
- Work to get notifications from messages without revealing context. You have several ways to get this, I will be in this case, I will provide the tasks gathered in a namespace. Those functions will call the message identifier as the first parameter and will return only one data from the message (if necessary it can be a complete object).
In this way, users can not use only data containers as structures because they do not have definitions, they can access sensor data.
There are two problems: clear display costs and it is clearly heavy to write and change. Perhaps it would be better to use some code generators. Google Protobuf is full of good ideas in this domain.
But the best way would be to understand that their way of working will break sooner or later.
Comments
Post a Comment