When we have completed this step, all of our SQL statements will be inside Gateway classes, and no longer in our page scripts or other non-Gateway classes. We will also have tests for our Gateway classes.

From here on out, any time we need to add new calls to the database, we will do so only in the Gateway classes. Any time we need to fetch or save data, we will use the Gateway methods instead of writing embedded SQL. This gives us a clear separation of concerns between the database interactions and our future model layer and entity objects.

Now that we have separated our database interactions into their own layer, we are going to inspect all the calls to the Gateway objects throughout the legacy application. We will examine how the returned results are manipulated by the page scripts and other classes, and begin extracting the behaviors that define our model layer.