Design Pattern Principe SOLID
Je me retrouve a faire un exercice d'entrainement : et je ne sais quel sont les principes qui ne sont pas respecter dans
cette conception ou Code :
je ne suis pas sure de ma réponse et je dis Liskov substitution .
a développez !!
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
public class App {
public static void main(String[] args) {
Greeting greeting = new Greeting();
greeting.sayHello(new Friend());
greeting.sayHello(new Enemy());
}
}
public class Greeting {
public void sayHello(Person person) {
person.greet();
}
}
public class Person {
public void greet(){System.out.println("Hello person");}
}
public class Friend extends Person {
public void greet() {
System.out.println("Hello my friend");
}
}
public class Enemy extends Person {
public void greet() {
{throws new UnsupportedOperationException();
}
} |