Wolfxyz16 / ShareTrip

ShareTrip is a carpooling application between individuals! 🚗🚗
GNU General Public License v3.0
1 stars 0 forks source link

Some suggestions to improve your code #111

Open juananpe opened 5 months ago

juananpe commented 5 months ago
  1. Use constructor chaining in the Driver and Traveler classes:

    • In the Driver class, modify the constructor with parameters to call the superclass constructor using super(email, userName, password) instead of setting the fields directly.
    • In the Traveler class, modify the constructor with parameters to call the superclass constructor using super(email, userName, password) instead of setting the fields directly.
  2. Remove unnecessary getters and setters:

    • In the Driver class, remove the getEmail(), setEmail(), and getUsername() methods since they are already inherited from the User class.
  3. Use List interface instead of Vector:

    • In the Driver class, change the type of the rides field from Vector<Ride> to List<Ride>. Vector is a legacy class and is generally replaced by ArrayList or List in modern Java development.
  4. Use @Override annotation consistently:

    • In the Driver class, add the @Override annotation to the equals() method to indicate that it is overriding the method from the superclass.
  5. Simplify the doesRideExists() method:

    • In the Driver class, the doesRideExists() method can be simplified using a stream and anyMatch():
      public boolean doesRideExists(City from, City to, Date date) {
       return rides.stream().anyMatch(r -> Objects.equals(r.getFromLocation(), from) &&
                                           Objects.equals(r.getToLocation(), to) &&
                                           Objects.equals(r.getDate(), date));
      }
  6. Override equals() and hashCode() methods in the Driver class:

    • In the Driver class, override the equals() and hashCode() methods based on the email field for proper object comparison and hashing.
  7. Remove unused methods

    • I think that the removeRide in the Driver class is not used
  8. Use the correct method names in the Message constructor:

    • It should be .getUsername instead of .getUserName