Several specific methods or one generic method?
<p>this is my first question after long time checking on this marvelous webpage.</p>

<p>Probably my question is a little silly but I want to know others opinion about this. What is better, to create several specific methods or, on the other hand, only one generic method? Here is an example...</p>

<pre><code>unsigned char *Method1(CommandTypeEnum command, ParamsCommand1Struct *params)
{
if(params == NULL) return NULL;

// Construct a string (command) with those specific params (params-&gt;element1, ...)

return buffer; // buffer is a member of the class 
}

unsigned char *Method2(CommandTypeEnum command, ParamsCommand2Struct *params)
{
...
}

unsigned char *Method3(CommandTypeEnum command, ParamsCommand3Struct *params)
{
...
}
unsigned char *Method4(CommandTypeEnum command, ParamsCommand4Struct *params)
{
...
}
</code></pre>

<p>or</p>

<pre><code>unsigned char *Method(CommandTypeEnum command, void *params)
{
switch(command)
{
case CMD_1:
{
if(params == NULL) return NULL;

ParamsCommand1Struct *value = (ParamsCommand1Struct *) params;

// Construct a string (command) with those specific params (params-&gt;element1, ...)

return buffer;
}
break;

// ...

default:
break;
}
}
</code></pre>

<p>The main thing I do not really like of the latter option is this,</p>

<pre><code>ParamsCommand1Struct *value = (ParamsCommand1Struct *) params;
</code></pre>

<p>because "params" could not be a pointer to "ParamsCommand1Struct" but a pointer to "ParamsCommand2Struct" or someone else.</p>

<p>I really appreciate your opinions!</p>
