【发布时间】:2011-06-03 19:34:17
【问题描述】:
现在我有一个配置阅读器类,它通过一个文本配置文件并将它找到的值添加到我之前声明的变量中。然后将所有这些变量传递给构造函数。不用说,它很乱,看起来像这样:
String buttonText = "";
String buttonPassword = "";
String buttonAction = "";
String buttonFont = "";
int buttonPosX = 0;
int buttonPosY = 0;
int buttonWidth = 0;
int buttonHeight = 0;
int buttonFontSize = 0;
int buttonFontColor = 0;
int buttonBgColor = 0;
int buttonLayoutPosition = 0;
// Gathering information here ...
parent.addButton(buttonText, buttonPassword, buttonPosX, buttonPosY, buttonLayoutPosition, buttonWidth, buttonHeight, buttonAction, buttonFont, buttonFontSize, buttonFontColor, buttonBgColor);
有没有更好的方法来做到这一点?我听说过地图,这是一个使用地图的好地方吗?我要牢记效率,还要考虑代码的可读性和维护性。
【问题讨论】:
标签: java variables performance maintenance readability