Fully transitive const is not necessary

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun Apr 27 07:14:19 PDT 2008


Walter Bright wrote:
> Steven Schveighoffer wrote:
>> "Walter Bright" wrote
>>> Sure, but static class members are *not* part of the transitive 
>>> closure state of the object. They're just global variables.
>>
>> Neither are mutable member variables.
> 
> How can a member not be a member of the state of an object?

If you have a tree node, you can have a member that is a link to the 
parent node. While the child nodes are considered part of the state of 
the tree node, the parent node is not. (That's why it's conceptually an 
optional member in such structure, unlike the child nodes).

Another example is a GUI widget object that has a link (aka a member) to 
it's Display (an class that represents the display properties where the 
GUI object will be rendered). The Display member is not part of the 
state of the GUI widget. It makes perfect sense to want const (or 
invariant) to restrict it's effect only to the other members of the GUI 
widget, but not the display member (and others which are not part of the 
logical state of the object).

It all comes down to the familiar concept of composition vs. aggregation.

I can give a link to an academic paper that details what I've mentioned, 
if you're still not convinced.

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list