BAEL-4007 Interface Segregation Principle (#9579)

Co-authored-by: Dhrubajyoti Bhattacharjee <dhrubajyoti.bhattacharjee@ul.com>
This commit is contained in:
Dhrubajyoti Bhattacharjee 2020-07-02 07:04:41 +02:00 committed by GitHub
parent 0f02de64a2
commit 70fe4a3ca9
8 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package com.baeldung.i.fixed;
public interface Bank extends Payment {
void initiatePayments();
}

View File

@ -0,0 +1,21 @@
package com.baeldung.i.fixed;
import java.util.List;
public class BankPayment implements Bank {
@Override
public void initiatePayments() {
}
@Override
public Object status() {
return null;
}
@Override
public List<Object> getPayments() {
return null;
}
}

View File

@ -0,0 +1,6 @@
package com.baeldung.i.fixed;
public interface Loan extends Payment {
void intiateLoanSettlement();
void initiateRePayment();
}

View File

@ -0,0 +1,26 @@
package com.baeldung.i.fixed;
import java.util.List;
public class LoanPayment implements Loan {
@Override
public void intiateLoanSettlement() {
}
@Override
public void initiateRePayment() {
}
@Override
public Object status() {
return null;
}
@Override
public List<Object> getPayments() {
return null;
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.i.fixed;
import java.util.List;
public interface Payment {
Object status();
List<Object> getPayments();
}

View File

@ -0,0 +1,32 @@
package com.baeldung.i.polluted;
import java.util.Collections;
import java.util.List;
public class BankPayment implements Payment {
@Override
public void initiatePayments() {
}
@Override
public Object status() {
return null;
}
@Override
public List<Object> getPayments() {
return Collections.emptyList();
}
@Override
public void intiateLoanSettlement() {
throw new UnsupportedOperationException("This is not a loan payment");
}
@Override
public void initiateRePayment() {
throw new UnsupportedOperationException("This is not a loan payment");
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.i.polluted;
import java.util.List;
public class LoanPayment implements Payment {
@Override
public void initiatePayments() {
}
@Override
public Object status() {
return null;
}
@Override
public List<Object> getPayments() {
return null;
}
@Override
public void intiateLoanSettlement() {
}
@Override
public void initiateRePayment() {
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.i.polluted;
import java.util.List;
public interface Payment {
void initiatePayments();
Object status();
List<Object> getPayments();
//Loan related methods
void intiateLoanSettlement();
void initiateRePayment();
}