RE: [boost] Re: Policy or Trait?

On Behalf Of E. Gladyshev Sent: Friday, 2 April 2004 1:34 PM To: boost@lists.boost.org Subject: Re: [boost] Re: Policy or Trait?
From: "Hurd, Matthew" <hurdm@sig.com>
[...]
It would be nice if something new like "aspect class" or some such could
Interesting name! I second your opinion in many ways.
Would be nice to stop the confusion / confounding by describing somewhat rigorously a classification / nomenclature for "aspect classes". Constant aspects (bad name?, plain? simpleton?) - static constants and types only (bad name) Static aspect - constant aspect extended to include static methods Base aspect - intended to be inherited from by a client aka common MCD policy class - policy aspect perhaps? Chain aspect - not sure how to describe this Recurring base aspect - a base aspect that requires the first parameter to be the client class, this is the CRTP. Generic "blah" aspect - "blah" parameterised by additional template parameters beyond the client e.g. generic recurring base aspect is the CRTP with additional params A generic base aspect class would describe much of the MCD style policy classes. A static aspect could be used in a base aspect like manner or without the inheritance. "Aspect" might be inappropriate as I'm not 100% on my AOP nomenclature, but it feels appropriate. A trait or policy could be classified in such terms which might avoid some confusion. Needs some work, but it might start something...
I don't think that differentiating between traits and policy makes too much sense or really necessary. As for now to me, they both are parts of the same concept. The idea is that a class can define an API specification. The user is responsible for implementing the API and supplying the implementation to the class as a template parameter.
Traditionally an API is not a set of just behaviors or just data structures. It is a combination of both and it doesn't have to be stateless.
So what's so unique about API's from the OOP standpoint especially. Well, an API as such cannot be INSTANTIATED. It just EXISTs as a set of rules, etc. It is like namespaces in C++. You cannot instantiate a namespace! You can instantiate data types defined by the API though.
So to me, both traits and policies are sort of interchangeable namespaces. Perhaps my view is too simplistic.
I sometimes do something like this
template< typename MatrixApi > struct equation_system_solver {...};
struct api { private: //** note private here api(); };
struct my_vector_api : api {...};
template< typename VectrorApi > struct my_matrix_api : api {...};
equation_system_solver< my_matrix_api<my_vector_api> > s;
Interesting. Especially handy I'd imagine if you use the CRTP with the api to give yourself some static polymorphism. Another pattern trait / policy style pattern I've used recently is having integer offsets and types associated with names in a type that represents a packet type, these "aspect classes" are combined with a packet type in a client to handle different financial exchanges in my case. This would be a "constant aspect" in my nomenclature above. It is a trait of a concept rather being a trait of a specific type or class. Gets interesting when one of those types in the constant aspect is a static aspect that describes operations on the type to be found at the offset indicated. The packet aspect is really nothing much more than a bunch integers and associated types and it feels like a trait (it is a trait of a concept); it is used like a policy. $0.002 Regards, Matt Hurd _______________________ Susquehanna Pacific P/L hurdm@sig.com +61.2.8226.5029 _______________________ IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

"Hurd, Matthew" <hurdm@sig.com> wrote in message news:BA1220310B07EC4A8E321B451E07AF47314478@msgbal501.ds.susq.com...
[...] "Aspect" might be inappropriate as I'm not 100% on my AOP nomenclature, but it feels appropriate. [...]
I don't think "aspect" as you're using it here has anything to do with AOP. From what I can tell, AOP is something like "function prologue/epilogue code injection". That is, given a function, you can modify it with an aspect that causes certain code to run before or after it (sorta). I think of it as "RAII on 'roids". Anyway, it seems to me that AOP is all about functions, while the current thread is about GP, so I think this is a very confusing use of the term "aspect". Dave --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.581 / Virus Database: 368 - Release Date: 2/9/2004

David B. Held wrote:
"Hurd, Matthew" <hurdm@sig.com> wrote in message news:BA1220310B07EC4A8E321B451E07AF47314478@msgbal501.ds.susq.com...
[...] "Aspect" might be inappropriate as I'm not 100% on my AOP nomenclature, but it feels appropriate. [...]
I don't think "aspect" as you're using it here has anything to do with AOP. From what I can tell, AOP is something like "function prologue/epilogue code injection". That is, given a function, you can modify it with an aspect that causes certain code to run before or after it (sorta). I think of it as "RAII on 'roids". Anyway, it seems to me that AOP is all about functions, while the current thread is about GP, so I think this is a very confusing use of the term "aspect".
I'm not an expert in anything, but in my mind the aspect side of AOP is a about being able to separate out different "aspects" of a design in a similar way to what you can achieve with C++ policies. Usually they are orthogonal but they don't have to be. And that's about it really. The epilogue/ prologue stuff and the weaving comes down to specific implementations. Aspect J is most comment probably, but it is not the only way. As I think about it, the epilogue prologue approach is just one way of wrapping stuff, but the most obvious way if the concept has not been design for an aspect. You can hardly shove a bunch of intrusive logic in the middle of an arbitrary loop in a method, or can you? Generic parameters are another way of introducing aspects, but the difference is that the class has to be designed for it which is not a flexible. You could chain together C++ types with an epilogue and prologue static methods, or some such, that could provide a similar mechanism but the weaving would be manual to the methods (could be automatic to the class via the raii style) unless you used some trickery overloading ->, clever proxying or some such like Stroustrup has with his locking paper from memory. Maybe you could call such an aspect an aspect aspect ;-) A lot of what policies is about (but not everything) is really giving a lot of the same capability to C++. Aspect still seems like a good name to me. It would be good to have some standard naming conventions / classifications in boost or as documented boost speak at least... Regards, matt.
participants (3)
-
David B. Held
-
Hurd, Matthew
-
Matt Hurd