The first scenario is the typical case in which it is
recommended to use the extract method refactoring, when there is duplicated code
in two or more methods and we want to take this
code and factor is out, and basically have the two methods called
a third method, which is the one we create using the
refactoring. When a class is too large, normally we don't want to
apply the extract. Extract method. Instead, in this cases, it is
usually more appropriate to use the
extract class or extract subclass refactorings.
Analogously, when the names of two classes are too similar, extracting a
method will normally not help much. And all we need to do
in case having too similar names is actually a problem. Is to
rename one of the two classes, or both, if we wish. Finally,
it is definitely appropriate to apply the extract method of refactoring in
cases in which a method is highly coupled with a class other
than the one where it is defined. In this case, which we
will discuss also later in the lesson, the extract method of refactoring
allows us to extract part of the metal to With the other class.
Then we can take the matter that we just extracted and move it
to the class where it actually belongs. So the extract method is one
of the two refactorings that it is appropriate to apply in these cases.