C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What's this C++ design pattern called?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
steve@stevejay.net
Guest





PostPosted: Sun Jul 17, 2005 8:30 pm    Post subject: What's this C++ design pattern called? Reply with quote



Hi there,

This design pattern is a way of avoiding having to have a constructor
with a long parameter list. A separate class is used to deal with
setting the parameter values, using setter functions that return *this
so that as many or as few as are required can be changed together.
Here's just a skeleton of an example:

class parameters
{
public:
parameters () {}

parameters & setting_a () { return *this; }
parameters & setting_b () { return *this; }
};

class something_useful
{
public:
something_useful (const parameters & p) {}
};

Using the above two classes, I can write:

something_useful my_useful (parameters().setting_a().setting_b());

I'd really like to know what this design pattern's "official" name is!

Thanks,
Steve


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Maciej Sobczak
Guest





PostPosted: Mon Jul 18, 2005 1:01 pm    Post subject: Re: What's this C++ design pattern called? Reply with quote



[email]steve (AT) stevejay (DOT) net[/email] wrote:

Quote:
This design pattern

I would not call it a "design pattern", since there is no real
collaboration between objects that this "pattern" would encapsulate.

It is just a coding technique, with the scope limited to a single
function (note that it does not have to be a constructor for this
technique to be useful).

It is possible that it has some established name, although I'm not aware
of any.


--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Fabio Fracassi
Guest





PostPosted: Mon Jul 18, 2005 1:02 pm    Post subject: Re: What's this C++ design pattern called? Reply with quote



[email]steve (AT) stevejay (DOT) net[/email] wrote:

Quote:
Hi there,

class parameters
{
public:
parameters () {}

parameters & setting_a () { return *this; }
parameters & setting_b () { return *this; }
};

class something_useful
{
public:
something_useful (const parameters & p) {}
};

Using the above two classes, I can write:

something_useful my_useful (parameters().setting_a().setting_b());

I'd really like to know what this design pattern's "official" name is!

Thanks,
Steve



The C++ FAQ calls this "named parameter ideom".
see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
I think that ideom fits better than design pattern for this, too, but that
is probably a matter of taste.


HTH

Fabio

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
leonardo77
Guest





PostPosted: Mon Jul 18, 2005 1:57 pm    Post subject: Re: What's this C++ design pattern called? Reply with quote

[email]steve (AT) stevejay (DOT) net[/email] wrote:
Quote:
I'd really like to know what this design pattern's "official" name is!

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
steve@stevejay.net
Guest





PostPosted: Tue Jul 19, 2005 9:29 am    Post subject: Re: What's this C++ design pattern called? Reply with quote

Hi,

Fabio Fracassi wrote:
Quote:
The C++ FAQ calls this "named parameter ideom".
see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
I think that ideom fits better than design pattern for this, too, but that
is probably a matter of taste.

That's where I'd seen it discussed! Thanks very much, to you and
leonardo77.

As for the design pattern/idiom thing, I'm just a beginner so the
language of this field is still quite slippery for me.

Bye,
Steve


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.