Graeme Geldenhuys schrieb:
On 29/08/12 17:24, Hans-Peter Diettrich wrote:
How do you intend to implement string operators?
I haven't thought or got to that part yet. I'll start with .Append(),
.Equals(), .Replace(), .SubString(), .Split() etc to cover all bases.
I'm still deciding if the TString class must be immutable or not. With
my strong Design Patterns background, I'm strongly leaning towards that
though. So .Append() and .Replace() for example will return new
instances of the class.
This is just what can make such classes dead slow in real life use.
The classic unit test Money example explains this "immutable" reasoning
well. Consider the following...
public void testMultiplication() {
Dollar five = new Dollar(5);
five.times(2);
assertEquals(10, five.amount); // Confusing!
Now replace "five" by "MyAccount", and feel comfortable with the
continued increase :-)
In a good C++ design one would implement both "+" and "+=" operators, so
that a compiler has a chance to optimize expression evaluation.
DoDi
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus