By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,302 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,302 IT Pros & Developers. It's quick & easy.

need to find a design pattern

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"coeng" <fo***@kingstonroad.com> wrote...
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
Jul 22 '05 #2

P: n/a
A Message factory should do the job. The following article should
help:

http://www.eventhelix.com/RealtimeMa...ce_pattern.htm

You should define a message class hierarchy to handle cases where the
same field has to be obtained from a different offset.

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in
PDF
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.