by Mark Seemann Temporary Field is a well-known code smell. Here's an example and remedy. The Temporary Field code smell was described more than a decade ago, but I keep encountering it when doing code reviews. Despite its vintage, I couldn't find a good example, so I decided to provide one. The code smell is described in Refactoring : "Sometimes you see an object in which an instance variable is set only in certain circumstances. Such code is difficult to understand, because you expect an object to need all of its variables. [...] "A common case of temporary field occurs when a complicated algorithm needs several variables. Because the programmer didn't want to pass around a huge parameter list (who does?), he put them in fields." - Refactoring , Martin Fowler et al., Addison-Wesley 1999. p. 84 Unfortunately, Refactoring doesn't provide an example, and I couldn't find I good, self-contained example on the web either. Example: estimate a duration In this example,
Read full article from Temporary Field code smell
No comments:
Post a Comment