|
|
|
|
|
by safety-third
2316 days ago
|
|
No, it is very much LSP compliant. The purpose of toString() is to give a string representation of the object. Most overloads of this do exactly that. An LSP violation of toString() would be something that returns a string that doesn't represent the object. If you were to return the current time as a string for an object that has nothing to do with time, that would be an LSP violation. |
|
> Subtype Requirement: Let ϕ(x) be a property provable about objects x of type T. Then ϕ(y) should be true for objects y of type S where S is a subtype of T.
Why is the exact value of the string returned not a provable property? And, to your example, if a provable property is that the returned string represents the object, how did you know it was a provable property? And how do you prove it?
The rule seems very formal, but your notions seem very informal, and I don't know how to reconcile them.