Re: template method gof pattern
From: Arnaud Debaene (adebaene_at_club-internet.fr)
Date: 12/08/04
- Next message: Igor Tandetnik: "Re: What determines the icon"
- Previous message: Dave Cullen: "What determines the icon"
- In reply to: John: "template method gof pattern"
- Next in thread: Igor Tandetnik: "Re: template method gof pattern"
- Reply: Igor Tandetnik: "Re: template method gof pattern"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 8 Dec 2004 19:57:23 +0100
John wrote:
<snip>
You should :
- Call CTest constuctor before CStrategyBase constructor. Although not
strictly necessary in your case, it is a better style to pass a complete,
initialized CTest to CStrategyBase constructor.
- Use an explicit cast to remove the ambiguity about the constructor
overload to call.
Also, if you are not sure about using inheritance vs aggregation for
embedding a CTest into CCompositor, perhaps you should choose private
inheritance instead of public inheritance to avoid the "is-a" relationship
(Liskov principle). However, I cannot say for sure since I don't understand
what is the semantic of your classes.
Arnaud
MVP - VC
Corriged version :
class CTest
{
private:
int i_;
public:
int getI() { return i_; }
void setI(const int rhs) { i_ = rhs; }
// Construction ------------------------------------------------
// Copying - no copy allowed, no assignment allowed
private:
CTest(const CTest& b) {}
CTest& operator=(const CTest& a) { return *this; }
// Construction
public:
CTest() : i_(1) {}
~CTest() {}
};
class CStrategyBase
{
private:
int k_;
protected:
CTest& test_;
public:
int getK() { return k_; }
void setK(const int rhs) { k_ = rhs; }
// Construction --------------------------------------------------
// Copying - no copy allowed, no assignment allowed
private:
CStrategyBase(const CStrategyBase& b) : test_(b.test_) {}
CStrategyBase& operator=(const CStrategyBase& a) { return *this; }
// Construction
public:
CStrategyBase(CTest& t) : test_(t), k_(1) {}
virtual ~CStrategyBase() {}
};
class CCompositor : private CTest, public CStrategyBase
{
private:
int m_;
public:
int getM() { return m_; }
void setM(const int rhs) { m_ = rhs; }
// Construction -------------------------------------------------
// Copying - no copy allowed, no assignment allowed
private:
CCompositor(const CCompositor& b) : CStrategyBase(b.test_) {}
CCompositor& operator=(const CCompositor& a) { return *this; }
// Construction
public:
CCompositor() : m_(1), CStrategyBase(*static_cast<CTest*>(this)) {}
//call CTest constructor before CStrategyBase constructor.
virtual ~CCompositor() {}
- Next message: Igor Tandetnik: "Re: What determines the icon"
- Previous message: Dave Cullen: "What determines the icon"
- In reply to: John: "template method gof pattern"
- Next in thread: Igor Tandetnik: "Re: template method gof pattern"
- Reply: Igor Tandetnik: "Re: template method gof pattern"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|