liveBook · Manning

Method extension

As explained in The Art of Code

Method extension is an API evolution technique that expands an existing method to support additional behavior while retaining its earlier use.

Method extension evolves an existing API by adding support for new behavior while preserving the earlier call pattern. Optional parameters let older clients continue working without endpoint proliferation. section 9.4.2

Keep the old call valid

A report-generation method can gain new options while clients using the original form continue unchanged. If the earlier method is eventually replaced, mark it deprecated and leave it available long enough for migration. section 9.4.2

This technique minimizes disruption and avoids maintaining multiple endpoints. Use it carefully: repeated extensions can make a method complex and ambiguous. Compatibility adapters and versioned entry points remain alternatives when one interface can no longer express change clearly. section 9.4.2

@Deprecated(since = "2.1", forRemoval = true)
public void generateReport() { ... }

See a deprecation annotation marking an older method for removal while preserving a migration window. section 9.4.2

How The Art of Code covers it

How deep it goes
Explains optional-parameter support, benefits, and ambiguity risks, but stops short of implementation details.
Examples
Uses optional parameters and a Java deprecation annotation as concrete compatibility examples.
What it assumes
Assumes familiarity with APIs and client dependencies; teaches the compatibility concern motivating interface evolution.
What you can do after
Evaluate API changes and choose extensions, adapters, or versioning while giving clients time to migrate.
How it connects
Connects backward compatibility with deprecation, compatibility adapters, versioning, and API contracts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.