I agree with you Mark to some point. I try to avoid property getters
with observable side effects, like a "get and advance" property. Those
I usually split in a pure getter and a "command" Next() that advances to
the next item.
The base libraries also use this idiom, see for instance enumerators
where you have a "Current" property and a void "MoveNext() " command.
A property that changes internal state but has no observable effect is
used more often. For instance on first access of some "expensive"
property a value is fetched/calculated and cached. This will not change
the external view of your class but you must expect that during
debugging the cached values *can* be calculated or fetched at different
moments then running stand-alone.
A fun one is having logging active in a property getter, safe but
your logs can look strange (filled with unexpected entries) after a
debugging session. :-)
But I agree that it's sometimes useful to have a property with *real*
side-effects and like Jesse pointed out, you can hide or sanitize these
for the Debugger using the
DebuggerBrowsab le(DebuggerBrow sableState.Neve r)
DebuggerHidden( )
DebuggerDisplay ("some safe info about the property")
attributes.
An example of an "get and advance" property is a UniqueID class. The
class is responsible to never return the same ID twice so encapsulation
requires a property with side-effects. :-) You could also argue that in
this case you don't make a property but a function NextID() to make it
clear it's not *just* a property.
-- Freddy
Jesse Houwing schreef:
* Mark Wilden wrote, On 29-6-2007 20:45:
>"Freddy Potargent" <fr************ **@amcnv.bewrot e in message
news:9q******* ************@ph obos.telenet-ops.be...
>>A proper OO design will have only simple and pure property getters
The only OO design characteristic I think fits here is encapsulation,
and that would say that whether a property access has side-effects is
completely up to the owner of the property.
If a property is dangerous in the way that it has altering behavior on
it's getter, you can mark it to hide it from the debugger altogether.
Jesse