need to find a design pattern

C

coeng

I've run into a little problem with an OO design.

Suppose I have a class called "Message".

Each time I receive a communication from an external source, I
instantiate an object of class "Message".

A "Message" object consists of five 16-bit words and is a raw copy of
the payload of the communication just received.

A "Message" object contains various fields of data, some short in
length, some long, and some of which can span across word boundaries.
Some of are interest to my application, others are not. Some fields
are common to all messages, others are common to a subset.

The first "n" bits of the 1st 16-bit word are used to identify the
"message type".

The "message type" is then in turn, used to determine how to decode
the remaining fields in the remaining words of the message.

For example, if the message type is "message A" then "fieldX" appears
in the fourth word. If the message type is "message B" then "fieldX"
appears in the fifth word. Assume there exist "messages C thru Z".

I basically want to do something like this (in pseudocode):

instantiate a Message object upon receiving message from a source;
decode fieldX with something like...(fieldX = thisMsg->getfieldX();

What I don't want is something like this:

instantiate a Message object upon receiving message from a source;
if (thisMsg == message A) fieldX = extract bits from 4th word
if (thisMsg == message B) fieldX = extract bits from 5th word
if (thisMsg == message C) fieldX = extract bits from 1st word
.....
.....
if (thisMsg == message Z) fieldX = extract bits from 2nd word

I was doing some reading on the bridge pattern and how I could
possibly apply it here, but I don't feel like it would apply in this
situation. In order to implement the bridge pattern, the
implementation (i.e. the correct bit extraction for fieldX) needs to
be known for the abstraction (i.e. the particular message type) a
priori. The first "n" bits of a message determine how fieldX is
extracted. This information is not known until a Message object is
created and its first "n" bits are decoded.

Any help would be appreciated. Thanks.
 
V

Victor Bazarov

coeng said:
I've run into a little problem with an OO design.
[...]

There are at least two newsgroup that IMHO are more
suitable for your questions than this one: comp.object
and comp.software.patterns.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top