From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-05-24 08:51:56
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
>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
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
com::msxml::XMLDOMNode node = ...;
std::cout << node.nodeName << " = " << node.nodeValue << '\n';
which would look very ugly without properties!
It's fast, it's easy and it's free. Get MSN Messenger today!
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk