7 Extensibility and Flexibility

This chapter covers:

  • Using inversion of control to make code flexible
  • Using interfaces to make code extensible
  • Adding new features to your existing code

At many established organizations, your day-to-day work as a developer involves not only writing new applications, but updating existing ones. When you’re tasked with adding a new feature to an existing application, your goal is to extend the functionality of that application with new behaviors. Extending software is the introduction of new behavior by the addition of code. Some applications are flexible to this kind of change, whereas others may fight you tooth and nail! Flexibility is how easily software can adapt to shifting requirements. In this chapter you’ll learn strategies you can use to write software that’s flexible and extensible by adding an "Import GitHub stars" feature to Bark.

7.1  What is extensible code?

Extensibility is all about the addition of new behaviors. Code is said to be extensible if adding new behaviors to it has little or no impact on existing behaviors. Said another way, software is extensible if adding new behavior involves adding new code without changing existing code.

7.1.1  Adding new behaviors

7.1.2  Modifying existing behaviors

7.1.3  Loose coupling

7.2  Solutions for rigidity

7.2.1  Letting go: inversion of control

7.2.2  The devil’s in the details: relying on interfaces

7.2.3  Fighting entropy: the robustness principle

7.3  An exercise in extension

7.4  Summary