caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Corey O'Connor" <coreyoconnor@gmail.com>
To: david.baelde@ens-lyon.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Heritage
Date: Thu, 15 Sep 2005 15:15:36 -0700	[thread overview]
Message-ID: <c129123505091515152dda3409@mail.gmail.com> (raw)
In-Reply-To: <53c655920509151501140404d@mail.gmail.com>

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


  reply	other threads:[~2005-09-15 22:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-15 20:48 Heritage David Baelde
2005-09-15 21:25 ` [Caml-list] Heritage Corey O'Connor
2005-09-15 22:01   ` David Baelde
2005-09-15 22:15     ` Corey O'Connor [this message]
2005-09-15 22:38       ` skaller
2005-09-15 22:58         ` Corey O'Connor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c129123505091515152dda3409@mail.gmail.com \
    --to=coreyoconnor@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=david.baelde@ens-lyon.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).