hellerim (22) [Avatar] Offline
This sidebar is not very illuminating but looks rather contrived. The Java code presented here is by no means realistic, at least if you want to present quality OO code. The method plotRouteOnMap() and calculateTime() depend on the route member of the class only; why not make them instance methods of route's class? Also, getShortestRoute() depends on its Location arguments and returns an instance of route's class; it might be better a static method of the Location class or a static method of route's class, or else a static or instance method of a factory class for route's class. Anyway, the three methods each appear to have a single responsibility. The plot() method of class DrivingDirections uses them. Somewhere in your code you need more than just one method call in a method. So, the plot() method here does not do the work itself but delegates this responsibility to the three other methods and calls them only. And this is ok. By the way, the return type of plot() is void, so you can't expect anything else but side effects from it.

Single responsibility is a principle which applies to OOP as well as to FP. In OOP, it's also a key ingredient for testability.

Message was edited by: