Cags
Contributor
I recently had a rough old time trying to work out why the TimeSpan's Add method wasn't working correctly. I eventually worked out it was because I was having a blonde moment and rather than actually adding a TimeSpan, it returns a new instance with the TimeSpan added. Basically I'm wondering what design decision(s) lean towards making a method work in such a manner?
I believe this follows the Factory design pattern? But I just cannot see why it was choosen in this case. To me at least the name of the method seems to imply it will add it to the current instance, not return a new instance with it added. If it was going to behave like this I would have expected a method called GetCombinedTimes or something that indicates you are creating a new object.
The more I think about this the more I think perhaps it has something todo with my good friend (yeah right) reference type vs value type. But there is no reason why a method of a value type cannot change one of its internal values, like the Offset method of a Rectangle does. Any thoughts?
I believe this follows the Factory design pattern? But I just cannot see why it was choosen in this case. To me at least the name of the method seems to imply it will add it to the current instance, not return a new instance with it added. If it was going to behave like this I would have expected a method called GetCombinedTimes or something that indicates you are creating a new object.
The more I think about this the more I think perhaps it has something todo with my good friend (yeah right) reference type vs value type. But there is no reason why a method of a value type cannot change one of its internal values, like the Offset method of a Rectangle does. Any thoughts?