Interface Segregation Prensibi Nedir ? (Kod örneğiyle) — SOLID

Interface Segregation Prensibi
Interface Segregation Prensibi
public interface Animal {
void fly();
void run(); void bark();
}
public class Bird implements Animal {
public void bark() {
/* do nothing */
}
public void run() {
System.out.println("Koşan kuş");
}
public void fly() {
System.out.println("Uçan kuş");
}
}
public class Cat implements Animal {
public void fly() {
/* do nothing */
}
public void bark() {
/* do nothing */
}
public void run() {
System.out.println("Koşan kedi");
// logic
}
}
Köpekler uçamaz mı?
public class Dog implements Animal {
public void fly() {
/* do nothing */
}
public void bark() {
System.out.println("Havlayan köpek.");
// logic
}
public void run() {
System.out.println("Koşan köpek.");
// logic
}
}
public interface Flyable {
void fly();
}
public interface Runnable {
void run();
}
public interface Barkable {
void bark();
}
public class Bird implements Flyable, Runnable {
public void run() {
System.out.println("Kuş,Koşuyorum");
//logic
}
public void fly() {
System.out.println("Kuş, Uçuyorum.");
//logic
}
}
public class Cat implements Runnable {
public void run() {
System.out.println("Kedi,Koşuyorum");
//logic
}
}
public class Dog implements Runnable, Barkable {
public void bark() {
System.out.println("Köpek,Havlıyorum.");
//logic
}
public void run() {
System.out.println("Köpek,Koşuyorum.");
//logic
}
}

--

--

Software Engineer @Yemeksepeti • #Java • #Spring Boot • #Kotlin • #Spark • #Microservices • https://gokhana.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gökhan Ayrancıoğlu

Gökhan Ayrancıoğlu

Software Engineer @Yemeksepeti • #Java • #Spring Boot • #Kotlin • #Spark • #Microservices • https://gokhana.dev