Revisiting users logged in to a service
In Chapter 2, Arrays: Foundational Structures, we created an app to keep track of users logged into a web service, using an array as the underlying data structure containing the
User objects. However, this design can be greatly improved upon by using a list data structure. Let's revisit the users logged into a service problem here, and by replacing the class array with a list, we will see that our original code is both abbreviated and more readable in most cases.
In this example, we have replaced the
User object with a
List<User> object. Much of this refactor is obvious, but three lines of code should be noted. First, in the
CanAddUser() method, we have replaced 15 lines of code with 2 lines of code by ...