If our application needs a Map of Sensors, you might find the sensors set up like this: Map sensors = new HashMap(); Then, when some other part of the code needs to access the sensor, you see this code: Sensor s = (Sensor)sensors.get(sensorId ); We don’t just see it once, but over and over again throughout the code. The client of this code carries the responsibility of getting an Object from the Map and casting it to the right type. This works, but it’s not clean code. Also, this code does not tell its story as well as it could. The readability of this code can be greatly improved by
...more
This highlight has been truncated due to consecutive passage length restrictions.