-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
The SuperPrinter Class in the ex02 package violates the Liskov Substitution Principle, it overrides the print mehtod making it to be able to throw an exception, even if in its super class printer is able to do so, it does not throw any exception, so it violates the Liskov Substitution Principle
You should change your Printer Class from:
`package org.afdemp.cb6.ex02;
public class Printer {
public void print(String message) throws PrinterNotEnabledException {
System.out.println(message);
}
}`
To the LSP Violation-free version:
`public class Printer {
private boolean enabled = true;
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public void print(String message) throws PrinterNotEnabledException {
if (!enabled) {
throw new PrinterNotEnabledException("The printer is not enabled");
}
System.out.println(message);
}
}
`
This way SuperPrinter is able to work correctly and you don't violate the Liskov Substitution Principle.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels