liveBook · Manning

Extensibility

As explained in Data-Oriented Programming: Reduce software complexity

Extensibility is the capacity of software to accommodate new functionality with minimal changes to existing code.

Extensibility is the capacity to add functionality with minimal changes to existing code. Polymorphism supports it by isolating animal-specific behavior, while a type-based switch forces new animals into the original function. section 13.1

Compare the design trade-off:

  • A switch-based greet function centralizes behavior, but adding an animal requires modifying that function. section 13.1
  • Object-oriented polymorphism lets a new animal class provide its own greeting without changing the existing animal-handling code. section 13.1
  • Multimethods are suggested as a way to pursue polymorphic extensibility without objects. section 13.1
Listing 13.2 A switch case where behavior depends on type
function greet(animal) {
  switch (animal.type) {
    case "dog":
      console.log("Woof Woof! My name is: " + animal.name);
      break;
    case "cat":
      console.log("Meow! I am: " + animal.name);
      break;
    case "cow":
      console.log("Moo! Call me " + animal.name);
      break;
  };
}

A compact switch example makes the maintenance pressure visible: each new animal case changes the central function. section 13.1

Animal greetings

Dog, cat, and cow records can share a type and name while greeting behavior remains selected by type. Splitting greetings into separate functions improves organization but still leaves the central dispatch function to modify.

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Contrasts switches, separate functions, classes, and multimethods, but stops short of explaining multimethod implementation.
Examples
Uses dog, cat, and cow greetings implemented through classes, maps, switches, and separate functions.
What it assumes
Assumes familiarity with switches and object-oriented classes while introducing multimethods as an alternative.
What you can do after
Evaluate whether a design lets new animal types extend behavior without modifying existing dispatch code.
How it connects
Connects extensibility with polymorphism, object-oriented programming, switch statements, and multimethods.

Also explained in

Compare how 7 books explain extensibility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.