Flexibility, maintainability, and refactoring

When we talked about decoupling in the previous section, the idea of flexibility and maintainability probably came to mind by association. Loosely coupled systems are more flexible and easier to maintain.

For example, in Chapter 6, Interfaces, Classes, and Object Construction, we demonstrated a flexible solution when implementing an object factory:

public static Calculator createInstance(){  WhichImpl whichImpl =       Utils.getWhichImplValueFromConfig(Utils.class,            Calculator.CONF_NAME, Calculator.CONF_WHICH_IMPL);  switch (whichImpl){    case multiplies:      return new CalculatorImpl();    case adds:      return new AnotherCalculatorImpl();    default:      throw new RuntimeException("Houston, we have another problem."+

Get Introduction to Programming 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.