PDA

View Full Version : Efficiency is the name of the game



baray98
19th September 2007, 17:56
I have a set of data as input and I my apps should decode it. This data contain different record type and each record type has different way of decoding them,, At the beginning of the data is a frame wrapper which contain the info on what type of record is it .

Now, my question what is the best way to handle this? Here is what i i did. I have a class Frame which handles the decoding of what record type it is then I have a class SpecificFrame that handles decoding of that record type which inherits class Frame. In my app I assign my void* vFrame to a SpecificFrame accordingly . I don't know if am being efficient on this style.

What's your take guys,

baray98

marcel
19th September 2007, 18:28
I am not sure if I understand you correctly, but why don't you create an abstract class that provides a basic interface for decoding records?
Assuming that there can be multiple ways of decoding multiple records, you should create as many subclasses of that abstract class as needed, one for each different decoding method.

As for the frame, you should have another class which contains the decoder classes. This class should parse a frame and instantiate decoder classes based on the decoding method needed(assuming the data in the frame provides info on the encoding type).

So, it should be pretty clean. No need to fiddle around with void pointers.

EDIT: in the class that handles the frame you should have only one member of the abstract class type. Then you could do:


AbstractDecoder *dec = null;
switch(decodingMethod)
{
case method1:
dec = new Method1Decoder();//here Method1Decoder is a subclass of AbstractDecoder that actually implements the decoding methods.
break;

...
}

baray98
19th September 2007, 18:48
yes that would be cleaner (my master ) marcel and thank you but can you give me examples of how can i implement the qouted below:



This class should parse a frame and instantiate decoder classes based on the decoding method needed(assuming the data in the frame provides info on the encoding type).



by the way the dataframe provides the encoding type

you are really my mentor,
baray98

baray98
19th September 2007, 18:50
sorry i havent read the code below your reply pardon me my master

marcel
19th September 2007, 19:11
:)
Ok, don't call me that.

wysota
19th September 2007, 19:42
:)
Ok, don't call me that.

Maybe we should change your user title on the forum? :cool:

marcel
19th September 2007, 19:45
Maybe we should change your user title on the forum? :cool:

Please don't :).
"Master" sounds like what British butlers call their employers( read "masters") :).

wysota
19th September 2007, 20:03
Yeah... or "Master" like in the master-slave architecture ;)