Replace constructor with factory method
Last modified: 08 March 2021
The Replace Constructor With Factory Method refactoring lets you hide a constructor and replace it with a static method which returns a new instance of a class.
Select the class constructor.
On the main or context menu, select Refactor | Replace Constructor With Factory Method.
In the dialog that opens, specify the name of the factory method and the class where the method should be created.
Preview and apply the changes.
Example
Before | After |
---|---|
|
|