Controlling program flow
One of the most basic things new developers learn is how programs execute lines of code in sequence and how if statements and other language features control what statements execute next.
In this section, we’ll focus on the BoardingProcessor
class's CanPassengerBoard
method. The method starts simple enough:
public string CanPassengerBoard(Passenger passenger) { bool isMilitary = passenger.IsMilitary; bool needsHelp = passenger.NeedsHelp; int group = passenger.BoardingGroup;
Here, CanPassengerBoard
takes in a Passenger
object and returns a string. The method also declares a few local variables holding pieces of data from the object passed in.
These variables aren’t necessary and could be removed by performing an inline variable refactoring, which we’ll talk about later in this chapter. However, as they improve the readability of the code that follows, their existence is largely helpful...