digitalmars.D.learn - Static class question
- Lubos Pintes (24/24) Feb 14 2013 Hi,
- anonymous (5/29) Feb 14 2013 Without 'static', StringItem objects would be tied to ListBox
Hi, I saw one ListBox class implementation. As we all know, ListBox class collects and displays strings. Author decided that he encapsulate the Object as item, and uses its toString() method when string is needed for display. For cases when string is added, he defined this small class, internal to ListBox: [code] private static class StringItem { private string _str; public this(string s) { this._str = s; } public override string toString() { return this._str; } } [/code] After I read about attributes on dlang, I think the static could be removed from above definition. Is this true? Thank
Feb 14 2013
On Thursday, 14 February 2013 at 12:49:01 UTC, Lubos Pintes wrote:Hi, I saw one ListBox class implementation. As we all know, ListBox class collects and displays strings. Author decided that he encapsulate the Object as item, and uses its toString() method when string is needed for display. For cases when string is added, he defined this small class, internal to ListBox: [code] private static class StringItem { private string _str; public this(string s) { this._str = s; } public override string toString() { return this._str; } } [/code] After I read about attributes on dlang, I think the static could be removed from above definition. Is this true? ThankWithout 'static', StringItem objects would be tied to ListBox objects. 'static' saves StringItem objects some bytes, and ensures that StringItem is independent of ListBox. See http://dlang.org/class.html#nested
Feb 14 2013