Assignment Group 20
Assignment Group 20
I. Definition:
The Interface Segregation Principle (ISP) is one of the five SOLID
principles of object-oriented design, which aims to create more
maintainable, scalable, and robust software.
V. Example
Let’s look into a situation where we’ve got a Payment interface
used by an implementation BankPayment:
public interface Payment {
void initiatePayments();
Object status();
List<Object> getPayments();
@Override
// ...
@Override
// ...
@Override
// ...
To develop this new feature, we’ll add the new methods to the
Payment interface:
// original methods
...
void intiateLoanSettlement();
void initiateRePayment();
@Override
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
}
@Override
In the next section, we’ll see how we can solve this problem.
Let’s break down the interface for each payment type. The
current situation:
Notice in the class diagram, and referring to the interfaces in the earlier section,
that the status() and getPayments() methods are required in both the
implementations. On the other hand, initiatePayments() is only required in
BankPayment, and the initiateLoanSettlement() and initiateRePayment() methods
are only for the LoanPayment.
With that sorted, let’s break up the interfaces and apply the Interface Segregation
Principle. Thus, we now have a common interface:
Object status();
List<Object> getPayments();
void intiateLoanSettlement();
void initiateRePayment();
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...
@Override
// ...