From: Gustavo Martin Morcuende Date: Thu, 24 Nov 2016 23:41:11 +0000 (+0100) Subject: Getting rid of variables in legacy code is great. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=b2f430882f5588a97e6f3c8e4dbe9415e36efb99;p=JavaForFun Getting rid of variables in legacy code is great. It enables us to reuse methods. Once we take away as many variables as posible we can remake optimizations. --- diff --git a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java index 264f2cd..aaa8992 100644 --- a/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/trip/TripService.java @@ -15,11 +15,16 @@ public class TripService { throw new UserNotLoggedInException(); } - List tripList = new ArrayList(); + // Getting rid of variables in legacy code is great because if we do it, + // it will be easier for us to refactor the code. + // Once we take away as many variables as posible we can remake optimizations + // but not before. + // We managed to get a symmetrical if (ternary operation) if (user.isFriendsWith(loggedInUser)) { - tripList = tripsBy(user); + return tripsBy(user); + } else { + return new ArrayList<>(); } - return tripList; } protected List tripsBy(User user) {