I have a legacy class that is rather complex to maintain:
class OldClass {
method1(arg1, arg2) {
... 200 lines of code ...
}
method2(arg1) {
... 200 lines of code ...
}
...
method20(arg1, arg2, arg3) {
... 200 lines of code ...
}
}
The methods are huge, unstructured, and repetitive (developer loved copy/paste aprroach). I want to split each method into 3-5 small functions, with one pulic method and several helpers.
What would you suggest? Several ideas come to my mind:
-
Add several private helper methods to each method and join them in #region (straight-forward refactoring)
-
Use Command pattern (one command class per OldClass method in a separate file).
-
Create helper static class per method with one public method & several private helper methods. OldClass methods delegate implementation to appropriate static class (very similiar to commands).
-
?
Thank you in advance!
SRP – Single Responsibilty principle and DRY – Don’t Repeat yourself