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.

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!
   five.times(3);
   assertEquals(15, five.amount);  // Fail! It's actually 30 now.
}

After calling .times() the five dollar instance isn't 5 any more! Quite confusing, and probably a good thing to avoid. So the following makes a lot more sense.

public void testMultiplication() {
   Dollar five = new Dollar(5);
   Dollar product = five.times(2);
   assertEquals(10, product.amount);
   product = five.times(3);
   assertEquals(15, product.amount);
}

Now we can call five.times(x) all day long, and the five money instance is always 5.

Cheers,
  - Graeme -

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to