Click here to Skip to main content
15,916,379 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Different methods in objects in a List Pin
BadKarma18-Mar-08 2:54
BadKarma18-Mar-08 2:54 
GeneralRe: Different methods in objects in a List Pin
Cedric Moonen18-Mar-08 3:11
Cedric Moonen18-Mar-08 3:11 
GeneralRe: Different methods in objects in a List Pin
CPallini18-Mar-08 5:11
mveCPallini18-Mar-08 5:11 
GeneralRe: Different methods in objects in a List Pin
Cedric Moonen18-Mar-08 5:34
Cedric Moonen18-Mar-08 5:34 
GeneralRe: Different methods in objects in a List Pin
Hanan88818-Mar-08 3:15
Hanan88818-Mar-08 3:15 
GeneralRe: Different methods in objects in a List Pin
BadKarma18-Mar-08 2:45
BadKarma18-Mar-08 2:45 
QuestionRe: Different methods in objects in a List Pin
CPallini18-Mar-08 3:00
mveCPallini18-Mar-08 3:00 
GeneralRe: Different methods in objects in a List [modified] Pin
Member 75496020-Mar-08 5:25
Member 75496020-Mar-08 5:25 
This pattern presents a maintenance problem to me. What happens when you add more CItem types? How useful is CNode if the code needs to detect the type of the contents?

The solution to me is to specialize the CNode class for the different CItems it holds,

// generic class
class CNode
{
public:
	virtual bool process() = 0
	{
		// common default function
	}
};

class CEmbossNode : public CNode
{
public:
	virtual bool process()
	{
		// access CItem or CEmboss data/functions
		return CNode::process();	// or call default
	}
protected:
	int GetOrientation() const  { return mnOrient; }
private:
	int mnOrient;
	CEmboss * mpItem;
}

class CAnnealNode : public CNode
{
public:
	virtual bool process()
	{
		// access CItem or CAnneal data/functions
		// or call default
	}
private:
	CAnneal * mpItem;
};

class CList
{
	// ...
	CNode * mpListHead;
}

The types are hidden behind a polynorphic interface. Adding new types requires the definition of the polymorphic interface. Each CItem knows what it is and can use special knowledge or do just the default action.

IMHO, these outwiegh the cost of the virtual function.

// edit: remove multiple EmbossNode declarations

modified on Monday, March 24, 2008 1:43 PM

GeneralDrawing pictures c++ win32 Pin
Hanan88818-Mar-08 1:45
Hanan88818-Mar-08 1:45 
QuestionRe: Drawing pictures c++ win32 Pin
David Crow18-Mar-08 3:25
David Crow18-Mar-08 3:25 
GeneralRe: Drawing pictures c++ win32 Pin
Hanan88818-Mar-08 3:33
Hanan88818-Mar-08 3:33 
GeneralRe: Drawing pictures c++ win32 Pin
Mark Salsbery18-Mar-08 7:06
Mark Salsbery18-Mar-08 7:06 
Generalchar * to TCHAR Pin
Royaltvk18-Mar-08 1:40
Royaltvk18-Mar-08 1:40 
GeneralRe: char * to TCHAR Pin
CPallini18-Mar-08 1:59
mveCPallini18-Mar-08 1:59 
GeneralRe: char * to TCHAR Pin
Royaltvk18-Mar-08 2:17
Royaltvk18-Mar-08 2:17 
GeneralRe: char * to TCHAR Pin
CPallini18-Mar-08 3:06
mveCPallini18-Mar-08 3:06 
GeneralRe: char * to TCHAR Pin
Rajesh R Subramanian18-Mar-08 4:11
professionalRajesh R Subramanian18-Mar-08 4:11 
GeneralRe: char * to TCHAR Pin
CPallini18-Mar-08 4:51
mveCPallini18-Mar-08 4:51 
GeneralRe: char * to TCHAR Pin
Mark Salsbery18-Mar-08 7:09
Mark Salsbery18-Mar-08 7:09 
GeneralRe: char * to TCHAR Pin
Cedric Moonen18-Mar-08 2:14
Cedric Moonen18-Mar-08 2:14 
QuestionRe: char * to TCHAR Pin
David Crow18-Mar-08 3:36
David Crow18-Mar-08 3:36 
General[Message Deleted] Pin
preeti sharma18-Mar-08 0:30
preeti sharma18-Mar-08 0:30 
AnswerRe: toolbar on a dialog box Pin
Rajesh R Subramanian18-Mar-08 1:11
professionalRajesh R Subramanian18-Mar-08 1:11 
Generalhourglass cursor not showing in thread Pin
josip cagalj18-Mar-08 0:27
josip cagalj18-Mar-08 0:27 
GeneralRe: hourglass cursor not showing in thread Pin
CPallini18-Mar-08 0:46
mveCPallini18-Mar-08 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.