Rename Class Pattern

There is an established class or type which is well known in a codebase but the name no longer describes it's function.

You are following the process of Evolving a Domain Language.

Problem

Because it's well known, collaborators have created a permanent association with this class. It resides in muscle memory for them and they'd rather not change it.

Solution

Create a new class with the better name. Migrate functionality to the new class.

Keep the old class file around so it can be found, but refer to the new class with a comment.

Action

Create new class with the new name.

Existing class should subclass the old one.

Promote methods from subclass to superclass.

Comment at top of old class what the new class is called and reference artifacts created from Evolving a Domain Language.

Create proxy methods that call super and print deprecation warnings.

(optional) Code review and merge.

Migrate existing calls to new class.

Code review and merge.

(optional) Inclusions of old class throw an exception.

Related