by Fatalist_ma · 6y ago · 0 comments
The example from the Stackoverflow link makes more sense: " ssert.AreEqual(20, rect.Height); ... because changing a rectangle's width does not affect its height. " Well, we may choose to not follow that assumption in our project. Let's say we're making a graphical editor, our rectangle could have various restrictions - like fixed proportions, max/min area, etc; so I can imagine how we may not have a guarantee that changing 1 side does not change another side. If it's just for general-purpose geometric calculations - then sure, but then it better be an immutable object.
I mean, you should not use inheritance for things like these but I don't think this always violates LSP.
No comments yet.