Objected oriented approach to structure inside structure
Posted
by
RishiD
on Programmers
See other posts from Programmers
or by RishiD
Published on 2012-12-05T14:54:48Z
Indexed on
2012/12/05
17:26 UTC
Read the original article
Hit count: 308
object-oriented
|object-oriented-design
This is for C++ but should apply to any OO language.
Trying to figure out the correct object oriented apporach to do the following (this is what I do in C).
struct Container {
enum type;
union {
TypeA a;
TypeB b;
};
}
The type field determines if it TypeA or TypeB object.
I am using this to handle responses coming back from a connection, they get parsed and get put into this structure and then based on the message type the appropriate fields get filled in.
e.g.
struct Container parseResponse(bufferIn, bufferLength);
Is there an OO approach for doing this?
© Programmers or respective owner