Cioe' se ho le classi concrete Wine e Beer che derivano dalla classe base Drink, il factory method in questione sara' ad esempio "Drink createDrink(string drinkType, DrinkConfiguration config)".
Ovviamente questo significa che si avranno anche le due classi concrete WineConfiguration e BeerConfiguration che derivano da DrinkConfiguration.
allora:
se il problema sono i parametri
forse questo potrebbe interessarti:
codice:
/* The program below illustrates passing a variable
* number of arguments using the following macros:
* va_start va_arg va_end
* va_list va_dcl (UNIX only)
*/
#include <stdio.h>
#define ANSI /* Comment out for UNIX version */
#ifdef ANSI /* ANSI compatible version */
#include <stdarg.h>
int average( int first, ... );
#else /* UNIX compatible version */
#include <varargs.h>
int average( va_list );
#endif
int main( void )
{
/* Call with 3 integers (-1 is used as terminator). */
printf( "Average is: %d\n", average( 2, 3, 4, -1 ) );
/* Call with 4 integers. */
printf( "Average is: %d\n", average( 5, 7, 9, 11, -1 ) );
/* Call with just -1 terminator. */
printf( "Average is: %d\n", average( -1 ) );
}
/* Returns the average of a variable list of integers. */
#ifdef ANSI /* ANSI compatible version */
int average( int first, ... )
{
int count = 0, sum = 0, i = first;
va_list marker;
va_start( marker, first ); /* Initialize variable arguments. */
while( i != -1 )
{
sum += i;
count++;
i = va_arg( marker, int);
}
va_end( marker ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}
#else /* UNIX compatible version must use old-style definition. */
int average( va_alist )
va_dcl
{
int i, count, sum;
va_list marker;
va_start( marker ); /* Initialize variable arguments. */
for( sum = count = 0; (i = va_arg( marker, int)) != -1; count++ )
sum += i;
va_end( marker ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}
#endif
e questo post:
http://www.daniweb.com/forums/thread113972.html#
i 3 punti sono un metodo per passare n parametri ad una funzione un po come il printf, solo che secondo me non è una gran soluzione perchè non so se si puo' utilizzare per metodi virtuali.
Io poi utilizzerei un abstract factory o un builder passando come parametro al metodo una classe che deriva da un interfaccia comune ma fa l'override dei metodi virtuali della classe base magari coi 3 punti costruendo tutto cio' che ti occorre in modo polimorfo .
sempre se è possibile fare l'override dei 3 punti.
A me pero' sembra un gran casino e il gioco non vale la candela.
scusa se ti ho fatto perdere tempo.