5 Fuse similar code together

This chapter covers

  • Unifying similar classes with Unify similar classes
  • Exposing structure with conditional arithmetic
  • Understanding simple UML class diagrams
  • Unifying similar code with Introduce strategy-pattern (P5.4.2)
  • Removing clutter with No interface with only one implementation (R5.4.3)

In the previous chapter, I mentioned that we are not finished with updateTile. It violates several rules, most notably Never use if with else (R4.1.1). We also worked to preserve the ||s in the code because they expressed structure. In this chapter, we explore how to expose more such structures in the code.

This is updateTile at the moment.

Listing 5.1 Initial

function updateTile(x: number, y: number) {
  if ((map[y][x].isStone() ...

Get Five Lines of Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.