Replace Method with Method Object
Problem You have a long method in which the local variables are so intertwined that you cannot apply Extract Method . Solution Transform the method into a separate class so that the local variables become fields of the class. Then you can split the method into several methods within the same class. Before After Before After Before After Before After Why Refactor A method is too long and you cannot separate it due to tangled masses of local variables that are hard to isolate from each other. The first step is to isolate the entire method into a separate class and turn its local variables into fields of the class. Firstly, this allows isolating the problem at the class level. Secondly, it paves the way for splitting a large and unwieldy method into smaller ones that would not fit with the purpose of the original class anyway. Benefits Isolating a long method in its own class allows stopping a method from ballooning in size. This also allows splitting it into submethods within the class,Read full article from Replace Method with Method Object
No comments:
Post a Comment