 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
steve@stevejay.net Guest
|
Posted: Sun Jul 17, 2005 8:30 pm Post subject: What's this C++ design pattern called? |
|
|
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
|
Posted: Mon Jul 18, 2005 1:01 pm Post subject: Re: What's this C++ design pattern called? |
|
|
[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
|
Posted: Mon Jul 18, 2005 1:02 pm Post subject: Re: What's this C++ design pattern called? |
|
|
[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
|
|
| Back to top |
|
 |
steve@stevejay.net Guest
|
Posted: Tue Jul 19, 2005 9:29 am Post subject: Re: What's this C++ design pattern called? |
|
|
Hi,
Fabio Fracassi wrote:
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 |
|
 |
|
|
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
|
|