Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Objective C

Applying Strategy Pattern in C++ Applications

Rate me:
Please Sign up or sign in to vote.
4.71/5 (15 votes)
8 Jan 2001 127.5K   1.1K   72  
When it is possible to have several different algorithms for performing a process, Strategy Pattern can be used to determine the best solution.
#ifndef _FILLER
#define _FILLER

#include "stdafx.h"

// List of predefined constants
#ifndef SUCCESS 
#define SUCCESS 0
#endif

#ifndef FAILURE
#define FAILURE -1
#endif

// Class CFiller for filling a rectangle
class CFiller
{
	// Constructor and Destructor
	public :
		CFiller();
		virtual ~CFiller();

	// Services
	public :
		INT			SetFillerText( LPCSTR );
		INT			SetFillerRange( INT, INT );
		INT			SetFillerPos( INT );
		INT			GetFillerPos();
		COLORREF	SetFillerColor( COLORREF & );
		COLORREF	SetFillerBkColor( COLORREF & );
		COLORREF	SetFillerTextColor( COLORREF & );
		virtual INT		DoFill( CWnd *, const CRect & ) = 0;

	// Attributes
	protected :
		CString		m_csText;
		INT			m_nMinVal;
		INT			m_nMaxVal;
		INT			m_nPos;
		COLORREF	m_FillerColor;
		COLORREF	m_FillerBkColor;
		COLORREF	m_FillerTextColor;
};


// Class CLToRFiller for Left to Right Filler
class CLToRFiller : public CFiller
{
	// Constructor and Destructor
	public :
		CLToRFiller();
		virtual ~CLToRFiller();

	// Services
	public :
		virtual INT DoFill( CWnd *, const CRect & );
};

// Class CRToLFiller for Right to Left Filler
class CRToLFiller : public CFiller
{
	// Constructor and Destructor
	public :
		CRToLFiller();
		virtual ~CRToLFiller();

	// Services
	public :
		virtual INT DoFill( CWnd *, const CRect & );
};
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Switzerland Switzerland
Kulathu Sarma is working as a Technology Manager for GoldAvenue, a company based in Geneva, Switzerland and responsible for supporting e-business initiatives of GoldAvenue in B2B and B2C Sectors. He has been programming in C/C++ for 9 years and actively working on Patterns for the past 5 years.

Comments and Discussions