Simple but painful steps for writing a better code

Last updated 1 year ago by Dmitry Zaytsev

java

Stop creating new objects inside a class

Unless those are data objects you creating or the class is a factory. Here is what I mean:

class VehiclesManager(val context: Context) {

fun getVehiclesNextToMe(): List { val api = VehiclesRetrofitApi(context) val currentLocation = LocationProvider.currentLocation()

return api.getVehicles()
    .filter { it.coordinates.distanceTo(currentLocation) < 100 }

}

}

Read full Article