From b2f430882f5588a97e6f3c8e4dbe9415e36efb99 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Fri, 25 Nov 2016 00:41:11 +0100 Subject: [PATCH] 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. --- .../java/org/craftedsw/tripservicekata/trip/TripService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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) { -- 2.1.4