I am always skeptical about names containing the word "And" as they aren't expressing a single concept. What about the ModelAndView class in Spring MVC? It is something the controller returns to indicate what view to render and optionally provide models (data) to be displayed in that view.
What is the single concept here? I think it may be called PresentationIngredients as the view and the models will be used to create the presentation.
What's your take? Or do you think ModelAndView is already good enough? Why not many people raised the problem before?
Sunday, April 25, 2010
Sunday, April 18, 2010
Refactoring challenge: finding a better name
A common code smell is that a name containing the word "And". For example, consider class below:
Both the IGetAndSet and ObjectAndGetSetter names contain the word "And". Why is it a bad thing? Because there are multiple concepts in the name (e.g., the concepts of getter and setter in IGetAndSet), indicating that the single concept has not been spelled out yet. For this case, for IGetAndSet, I think the single concept is "property". For ObjectAndGetSetter, the single concept is "property of a given instance". So, I'd change the code as:
Now the challenge: in Spring MVC there is a ModelAndView class:
How do you rename it? Or is it good enough? Post your suggestions as comments.
private final static class ObjectAndGetSetter
{
private final IGetAndSet getAndSetter;
private final Object value;
...
//getters and setters
}
public static interface IGetAndSet
{
public Method getGetter();
public Method getSetter();
}
Both the IGetAndSet and ObjectAndGetSetter names contain the word "And". Why is it a bad thing? Because there are multiple concepts in the name (e.g., the concepts of getter and setter in IGetAndSet), indicating that the single concept has not been spelled out yet. For this case, for IGetAndSet, I think the single concept is "property". For ObjectAndGetSetter, the single concept is "property of a given instance". So, I'd change the code as:
private final static class InstanceProperty
{
private final IProperty property;
private final Object instance;
...
//getters and setters
}
public static interface IProperty
{
public Method getGetter();
public Method getSetter();
}
Now the challenge: in Spring MVC there is a ModelAndView class:
public class ModelAndView {
/** View instance or view name String */
private Object view;
/** Model Map */
private ModelMap model;
...
}
How do you rename it? Or is it good enough? Post your suggestions as comments.
Subscribe to:
Posts (Atom)