We developed a class to account for clients, but some of the code was lost! Restore the code considering the following conditions:
- The repository must have a method for getting the number of clients.
- The repository should not give access to internal fields.
- We want to see the history of changes, so when adding a new client, the old repository should remain unchanged.
The following code should work:
val alice = Client("Alice")
val bob = Client("Bob")
val repository = Repository(List(alice))
println(repository.size == 1) // true
val updatedRepository = repository.add(bob)
println(repository.size == 1) // true
println(updatedRepository.size == 2) // true
This should not compile:
repository.clients