Re: [boost] Re: class properties: requestforpromotionand/orfastreview.

Peter Dimov wrote:
Reece Dunn wrote:
Peter Dimov wrote:
As a relatively simple example, consider a pair of integers (x, y) that has an invariant of x*x + y*y = 25, and try to move from (3, 4) to (4, 3) by using the X and Y properties.
Since the invariant is on both variables, neither can be set independant of each other, since you'd assume that changing one would invalidate the invariant. Therefore, the properties must be *readonly* to prevent modification. You'd have a function to set both values at the same time (e.g. moveto).
Exactly. Which is the C++ model: int x() const, int y() const, void set(int, int). Some purists even omit the set(): p = point(4, 3);
You can, of course, use "read only properties" instead of x() and y() but this changes nothing but syntax, not necessarily for the better, I might add.
It all depends on what you are using the properties for. I use them regularly when dealing with MS COM objects where the interfaces use get/set methods to interface with the underlying object. So you can use them more intuitively (especially when coupled with smart pointers, exceptions and variant/BSTR helpers): com::msxml::XMLDOMNode node = ...; std::cout << node.nodeName << " = " << node.nodeValue << '\n'; which would look very ugly without properties! Regards, Reece _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger

Reece Dunn wrote:
It all depends on what you are using the properties for. I use them regularly when dealing with MS COM objects where the interfaces use get/set methods to interface with the underlying object. So you can use them more intuitively (especially when coupled with smart pointers, exceptions and variant/BSTR helpers):
com::msxml::XMLDOMNode node = ...; std::cout << node.nodeName << " = " << node.nodeValue << '\n';
which would look very ugly without properties!
This is a circular logic. The reason that these COM interfaces use get_ and put_ prefixed member functions in their C++ form is because the original interface is property-based, and the reason for that is MS Visual Basic.
participants (2)
-
Peter Dimov
-
Reece Dunn