jnguyen095 / clean-code

Book review: A Handbook of Agile Software Craftsmanship

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boundaries - Using Third-Party Code

jnguyen095 opened this issue · comments

  • If our application needs a Map of Sensors, you might find the sensors set up like this:
    java Map sensors = new HashMap();
  • Then, when some other part of the code needs to access the sensor, you see this code:
    java Sensor s = (Sensor)sensors.get(sensorId );
  • 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 using generics, as shown
    below:
Map<Sensor> sensors = new HashMap<Sensor>();
...
Sensor s = sensors.get(sensorId );```