Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    I think you can run into trouble if you use mutable objects. A circle is also an ellipse. But if you replace an ellipse which is also a circle with another ellipse (which is what you are doing by using a setter method) there is no guarantee that the new ellipse will also be a circle (circles are a proper subset of ellipses). Commented Oct 24, 2012 at 15:23
  • 2
    In a purely functional world (with immutable objects), the method set_alpha_radius(d) would have return type ellipse (both in the ellipse and in the circle class). Commented Oct 24, 2012 at 15:25
  • @Giorgio Yes, I should have mentioned that this problem only occurs with mutable objects. Commented Oct 25, 2012 at 8:48
  • @KazDragon: Why would anyone substitute an ellipse with a circle object when we know that an ellipse IS NOT A circle? If someone does that, they do not have a correct understanding of the entities they are trying to model. But by allowing this substitution, aren't we encouraging loose understanding of the underlying system that we are trying to model in our software, and thus creating bad software in effect? Commented Jul 16, 2018 at 6:00
  • @maverick I believe you have read the relationship I described backwards. The proposed is-a relationship is the other way around: a circle is an ellipse. Specifically, a circle is an ellipse where the alpha and beta radii are identical. And so, the expectation might be that any function expecting an ellipse as a parameter could equally take a circle. Consider calculate_area(Ellipse). Passing a circle to that would yield the same result. But the problem is that the behaviour of the mutation functions of Ellipse are not substitutable for those in Circle. Commented Jul 17, 2018 at 14:45