
0
Planned
Divergent Change: Isn't it a bit different from Martin Fowler's book?
Hello,
I have just bought this lesson, its really awesome.
I have been reading the divergent changes section and I think the smell is a bit different on the Martin Fowler's book.
He says that,
"Divergent change occurs when one class is commonly changed in different ways for different reasons.
Well, I will have to change these three methods every time I get a new database; I have to change these four methods every time there is a new financial instrument," you likely have a situation in which two objects are better than one. That way each object is changed only as a result of one kind of change. Of course, you often discover this only after you've added a few databases or financial instruments. Any change to handle a variation should change a single class, and all the typing in the new class should express the variation. To clean this up you identify everything that changes for a particular cause and use Extract Class to put them all together." M.Fowler - Refactoring Improving the Design of Existing Code
But in your lesson, you say
"You find yourself having to change many unrelated methods when you make changes to a class. For example, when adding a new product type you have to change the methods for finding, displaying, and ordering products."
I understand that you said if a change happens and then you have to change different parts of your class, there is a divergent change code smell. And you suggest that you can Extract Method to fix this.
I think this does not reflect the purpose of the divergent changes smell. Because there must be at least two changes that affect different parts of your class. This mean that the class has at least two responsibilities and you should extract class to fix it. I think just extracting method is not a way to fix this situation. Because there are more than one responsibility of a class so you should extract the class. Extract method may be used if you extract and move it to another class.
I have just bought this lesson, its really awesome.
I have been reading the divergent changes section and I think the smell is a bit different on the Martin Fowler's book.
He says that,
"Divergent change occurs when one class is commonly changed in different ways for different reasons.
Well, I will have to change these three methods every time I get a new database; I have to change these four methods every time there is a new financial instrument," you likely have a situation in which two objects are better than one. That way each object is changed only as a result of one kind of change. Of course, you often discover this only after you've added a few databases or financial instruments. Any change to handle a variation should change a single class, and all the typing in the new class should express the variation. To clean this up you identify everything that changes for a particular cause and use Extract Class to put them all together." M.Fowler - Refactoring Improving the Design of Existing Code
But in your lesson, you say
"You find yourself having to change many unrelated methods when you make changes to a class. For example, when adding a new product type you have to change the methods for finding, displaying, and ordering products."
I understand that you said if a change happens and then you have to change different parts of your class, there is a divergent change code smell. And you suggest that you can Extract Method to fix this.
I think this does not reflect the purpose of the divergent changes smell. Because there must be at least two changes that affect different parts of your class. This mean that the class has at least two responsibilities and you should extract class to fix it. I think just extracting method is not a way to fix this situation. Because there are more than one responsibility of a class so you should extract the class. Extract method may be used if you extract and move it to another class.
Customer support service by UserEcho
You have already suggested extract class Im sorry I have misread this.
But I still think that "there must be at least two changes that affect different parts of your class. This mean that the class has at least two responsibilities" and the explanation that you did in your class is not clear about that.
Am I missing something?
I think we both mean the same thing but word it differently. In any case, I'll put a note to revisit this smell during my work on the second edition of the course and make the definitions more accurate. Thanks!
Thank you for your quick reply. I really liked the course. Especially the code diff parts.
Thanks... :)