Just Look at The Example Below The difference between the two if Condition
Do Not Do This
private final List<Carriage> carriages [...]
private int percentReservedBarrier = 70;
public void reserveSeats(ReservationRequest request) {
for (Carriage carriage : carriages) {
if (carriage.getSeats().getPercentReserved() <
percentReservedBarrier) {
request.reserveSeatsIn(carriage);
return;
}
}
request.cannotFindSeats();
}
Do This Instead
public void reserveSeats(ReservationRequest request) {
for (Carriage carriage : carriages) {
if
(carriage.hasSeatsAvailableWithin(percentReservedBarrier))
{
request.reserveSeatsIn(carriage);
return;
}
}
request.cannotFindSeats();
}
Top comments (0)