Timeline for Replace Method with Method Object v Principle of Least Visibility
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 22, 2017 at 20:17 | history | edited | Doc Brown | CC BY-SA 3.0 | added 608 characters in body |
| Jun 22, 2017 at 20:10 | history | edited | Doc Brown | CC BY-SA 3.0 | added 608 characters in body |
| Jun 22, 2017 at 18:40 | history | edited | Doc Brown | CC BY-SA 3.0 | deleted 172 characters in body |
| Jun 22, 2017 at 14:52 | history | edited | Doc Brown | CC BY-SA 3.0 | added 172 characters in body |
| Jun 22, 2017 at 14:33 | comment | added | Doc Brown | @TSar: well, I read "long computation" as "complex computation". And Fowler's example surely does not become better if one adds half a dozen methods to this class just to demonstrate it is complex enough to justify the usage of a class instead of a method. And I agree to you, replacing small and simple method by a class is also really bad, this is the kind of example the OP gave in the first link. | |
| Jun 22, 2017 at 14:29 | comment | added | T. Sar | ... and it should be done for the correct reasons. His didactic is misleading because he doesn't help a novice dev to find the correct reasons to do so. | |
| Jun 22, 2017 at 14:26 | comment | added | T. Sar | @DocBrown This example is bad because it shows a very simplified class and UML diagram to exemplify his point. "Long computation" (as in, takes a while to finish) isn't a good reason to do this type of thing - lots of parameters, need to check the state while the thing runs, shared memory space, etc - those things are good reasons. By reducing the problem to a example that looks trivial, it pushes the idea that this technique should be used on trivial stuff. He is 100% correct that this is a good way to refactor stuff... | |
| Jun 22, 2017 at 14:17 | comment | added | Walfrat | For me the "particular reason" is because you want that local variable to become a part of the state of your object even if it is currently used only by one method. | |
| Jun 22, 2017 at 14:00 | comment | added | Doc Brown | @TSar: well, I don't know which of Fowler's example you are referring to, but in my copy of the "Refactoring" book he speaks clearly about a long method with a long computation. | |
| Jun 22, 2017 at 11:51 | comment | added | T. Sar | This is all very good, however the other extreme is also true - replacing small and simple method by a class is also really bad. This is, like almost everything on software development, part of a spectrum of viable solutions which should be weighted for the problem at hand before being picked up, instead of because someone said X or Y. Fowler's example is bad because it gives the impression you should use this for trivial things. | |
| Jun 22, 2017 at 11:41 | history | answered | Doc Brown | CC BY-SA 3.0 |