Member variables and method names have an implied namespace. This is the name of the class and the package they live in. If you repeat this namespace everywhere the code becomes cluttered.
public class ViewPostController extends AbstractCommandController
{
public static final String VIEW_POST_VIEW_NAME = "viewPost";
private DataService viewPostDataService;
:
public Map getViewPostData()
{
:
}
}
In the above example, there is no need to include the prefix VIEW_POST_ again, since the namespace of the variable is already the ViewPostController. Anywhere the VIEW_POST_VIEW_NAME variable is referenced from outside the class, it would be written as ViewPostController.VIEW_POST_VIEW_NAME - which carries the words “view post” twice. It is redundant and tedious information.
ViewPostController.VIEW_NAME would be more concise, as below:
public class ViewPostController extends AbstractCommandController
{
public static final String VIEW_NAME = "viewPost";
private DataService dataService;
:
public Map getData()
{
:
}
}
The best way to make a call on the naming is to consider what the caller has to write when referencing the variable: will it be simple to code?