Thursday, 20 April 2017

TrafficControl: Refactoring the Train::move() function

There are some issues with the code in the tcTrain part of the program. The code needs to be refactored and when the train has reached the end of the TravelPlan, it is still looking for the next station.

Since the bug was easy to spot and fix, I've solved that first before refactoring. If I would have considered the bug to be difficult to solve, I would have considered refactoring first and debugging later.

The tcTrain::move() method covers some 170 lines of code that needs to be broken up to different methods.

First, I'll review the existing methods for tcTrain:


The tcTrain:move() method is based on some different states:


That method will call some new methods:

  • tcTrain;:waitingState
  • tcTrain::readyState
  • tcTrain::runningState
  • tcTrain::openingState
  • tcTrain::loadingState
  • tcTrain::closingState
  • and also some other helper methods/functions.

I'll remove the method tcTrain::getRouteVectorTracks().

The first step will be porting the code to the new methods without breaking anything...

No comments:

Post a Comment