开发者

Anything wrong with declaring variables like this?

So there are sort of 2 questions here.

In my database I need 18 fields because in golf there are 18 holes (so 18 to store hits for each hole开发者_StackOverflow中文版.) Second I need to store the yardage for each hole (so thats 18 more.)

My question is, right now I am declaring them all as follows:

public static final String KEY_H1 = "h1";
public static final String KEY_H1Y = "h1y";
public static final String KEY_H2 = "h2";
public static final String KEY_H2Y = "h2y";
public static final String KEY_H3 = "h3";
public static final String KEY_H3Y = "h3y";

etc.

h1 being hole 1 h1y being hole 1 yardage

Is there a better way to do this? Additionally, in the on create I will have to call h1 h1y h2 h2y h3 h3y etc.

Thanks in advance!

EDIT: 1. Will this tax the system a lot in terms of, cause the application to bomb out or run slower? 2. In the future, will this make it a pain to update the database?


You could instead of having a "golf game score" table, have a "hole score" table. This table could then contain an int column for the hole, another column for yardage, and another game_id column.


Tacking onto Kabuku's answer: Suppose for a given round of golf, you want to find out how many birdies, eagles, bogies, etc. the player had; or you want to find out which holes had the best score against par, which had the worst, etc. Do you really want to write the same code 18 times, once for each hole; or do you want to be able to write the code once, as a loop or query over the holes, to find the result?

This is just one reason why you really, really want to make the hole number a parameter, instead of creating separate static variables or columns for each hole.

To answer the other part of your question -- would it slow down the system to declare a lot of public static final variables -- the answer is no. But in this particular case, it would eventually slow you down.


I would just store it as a string, since you have fields for something from x to y, which should always be in some sort of array form. The easiest way, I think, is storing it as:

hits:yardage hits:yardage hits:yardageetc...

In your database, then splitting the string by : and .

(And in response to your edit, yes, your current way will probably make it unnecessarily difficult to update the database structure.)


I'd have two tables, a game table, and a hole score table.

The game table would have the date and course.

The hole score table would have the hole number, the yardage, the score and the _id of the record for the game in the game table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜