Chapter 6. Retrieving information
This chapter covers
- Using query methods for retrieving information
- Using single, specific return types
- Designing an object to keep internal data to itself
- Introducing abstractions for query calls
- Using test doubles for query calls
An object can be instantiated and sometimes modified. An object may also offer methods for performing tasks or retrieving information. This chapter describes how to implement methods that return information. In chapter 7 we’ll look at methods that perform a task.
Earlier, we briefly discussed command methods. These methods have a void return type and can be used to produce a side effect: change state, send an email, store a file, etc. Such a method shouldn’t be used for retrieving information. If you want to retrieve information from an object, you should use a query method. Such a method does have a specific return type, and it’s not allowed to produce any side effects.
Take a look at the Counter class.