Again, what Is a Design Pattern?


General structure of a design pattern solution


Four Essential Elements


Behavioral Design Patterns



Strategy


Solution 1


typedef void eogFunction (Player *pPtrs);


extern void hhcoEOGFunc (Player *pPtrs);


void

blah (eogFunction sF, Player *pPtrs)

{

(*sF) (pPtrs); // call whatever sort is passed in

}


void

main ()

{

const Int32 NUM_PLAYERS = 4;

Players thePlayers [NUM_PLAYERS];


// assume thePlayers is initialized somehow here


blah (hhcoEOGFunc, thePlayers);

}



switch (eogType)

{

case NORMAL:

blah (hhcoEOGFunc);

break;


case QUICK:

blah (quickEOGFunc);

break;


case DEBUG:

blah (debugEOGFunc);

break;

}


Solution 3


Key Elements of solution


class EOGFunction

{

public:

virtual void Sort (Players *pPtrs);

};


class hhcoEOGFunc : public EOGFunction

{

public:

virtual void Check (pPtrs);

};


class quickEOGFunc : public EOGFunction

{

public:

virtual void Check (pPtrs);


void SomeInitFunc (int, int, int);

};


Consequences


Summary