Version française
Home     About     Download     Resources     Contact us    
Browse thread
Heritage
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Corey O'Connor <coreyoconnor@g...>
Subject: Re: [Caml-list] Heritage
On 9/15/05, David Baelde <david.baelde@gmail.com> wrote:
> I don't think the decorator pattern fullfills my needs, cause it does
> not allow you to end up with one object having an added method from
> one decorator and an other one from a different decorator. You can
> compose decorators, but you'll only see the methods of the last one.

I don't follow your argument why a Decorator would not work. What do
you mean by "the last one"?
(Again sub-par C++ typed directly in Mail)

class IBuffer
{
public:
	virtual void SomeMethod() = 0;
}

class CBuffer : public IBuffer
{
public:
	void SomeMethod() = { //... Whatever... }
};

class CDiscoBufferDecorator : public IBuffer
{
	IBuffer* mDecorated;
	
public:
	CDiscoBufferDecorator(IBuffer* inBuffer) : mDecorated(inBuffer) {}
	
	void SomeMethod() = 
	{
		std::cout << "Disco!" << endl;
		mDecorated->SomeMethod();
	}
}

class CFancyBufferDecorator : public IBuffer
{
	IBuffer* mDecorated;
	
public:
	CFancyBufferDecorator(IBuffer* inBuffer) : mDecorated(inBuffer) {}
	
	void SomeMethod() = 
	{
		std::cout << "Not really that fancy... " << endl;
		mDecorated->SomeMethod();
	}
}

IBuffer* theFancyBuffer = new CFancyBufferDecorator(new CBuffer);
IBuffer* theDiscoBuffer = new CDiscoBufferDecorator(new CBuffer);
IBuffer* theDancyDiscoBuffer = new CFancyBufferDecorator(theDiscoBuffer);

Three instances that all conform to the Buffer interface but with
different "decorations".
So there would be one object with one decorator (theFancyBuffer) and
another object with another decorator (theDiscoBuffer).

Isn't that behavior what you want?

-- 
-Corey O'Connor