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 

policy container?

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





PostPosted: Thu Jun 26, 2003 7:36 pm    Post subject: policy container? Reply with quote



Everyone,


How can I design a container of policies?

So that it can be passed as to a class ctor?

Or is this even a good idea if I have 6 or more policies?

Thanks,
Jeff



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Juan J. Monroy
Guest





PostPosted: Sun Jun 29, 2003 10:15 pm    Post subject: Re: policy container? Reply with quote



Jeffrey Graham wrote:
Quote:
Everyone,


How can I design a container of policies?

I suppose that you could use an empty PolicyBase class like

class PolicyBase { };
class MyPolicy : PolicyBase { // implementation };
etc, . . . but I don't think it's a good idea.

Quote:
So that it can be passed as to a class ctor?

Or is this even a good idea if I have 6 or more policies?

Policy classes are orthogonal. So having a container of policies means

that the policies support the ISA relationship which in turn implies
that the policies are not orthogonal. Well, some policies aren't
completely orthogonal as they support some logical concepts.
Multithreaded classes for example support a lock(), unlock() so they
could derive from a LockBase ADT class just as Creators could derive
from a CreateBase ADT class that has a create(); but using a base class
is probably unnecessilary complex for small simple policy classes.

The whole point of policies is to create more complex types by combining

simpler types using multiple inheritance and templates. for example,

class SingleThreaded { ... };
class Atomic { ... };
class Semaphore { ... };
template <class T> NewCreator { ... };
template <class T> MallocCreator { ... };

template <
template class ThreadPolicy
Quote:

class MyMgr : public CreatorPolicy, ThreadPolicy { ... };


class Widget { ... };

// Single Threaded class that uses new to create objects of type widget
MyMgr<NewCreator one;
// Semaphore controlled acceess that uses new to create objects of type
// widget.
MyMgr<NewCreator two;

Having policies in a container class won't allow you to inherit the
policies. You'll have to add a lot of plumbing to connect the class you
want to use to the different policies that your using. Kind of defeats
the point of policies. Hope that helps, the book Modern C++ Design is
filled with more information on policies and templates. It's a must read

book. If you have 6 or more policies it doesn't mean that you'll have 6
template parameters, maybe you only need 2. If you do need all 6
template parameters then I would expect more than 6 policies, otherwise
maybe that class doesn't really need to be designed by policy or not all

the parts of the class should be a policy. Just my thoughts.

P.S. sorry if I misspelled stuff, my brain doesn't seem to be working as

I can't find my spell check in mozilla . . . humph, weird. Probably need

more sleep.

[ 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.