Object-Oriented Programming 2022/23

Exercise 8



Present the working version of your program as instructed by the teachers.

Continue working on the project. Make a code revision – so-called refactorization – for the purposes of increasing the quality of the applied object-oriented design.



  1. Try the example with circle and ellipse from the lecture. Make sure you understand why deriving a circle from an ellipse leads to violating the Liskov substitution principle and design by contract. Change the example so that both circle and ellipse are derived from a common supertype. Note this prevents the increaseEllipse() method from being applied to circles.
  2. Recall task 6 from Exercise 6 (exceptions in overriding). Note how this is related to the Liskov substitution principle: extending a set of exceptions that a method draws in practice weakens postconditions because by this the method narrows a set of cases in which it ends favorably and by returning an expected result. This would constitute a problem for the client code, but, fortunately, unlike with a common Liskov substitution principle violation, the compiler directly warns against this mistake.

If necessary, go back to the tasks from previous exercises and discuss any uncertainties.


Valentino Vranić
vranic at stuba.sk