最近,我用 java MVC 框架编写了一个简单的游戏,一位高级程序员在审查后告诉我,得分是不安全的,其 getter 和 setter 在玩家模型本身中定义。不幸的是,我无法从他们那里获得更多关于如何以及为何如此的信息,而且我无法弄清楚为什么。
有人可以回顾一下这些类并指出为什么这种架构不可取吗?
播放器型号:
public class player implements Comparable<player>{
private int score;
private int consecutive_misses;
private String name;
private int foul_count;
private int turn;
private boolean win;
public player()
{
this.score=0;
this.consecutive_misses=0;
this.foul_count=0;
this.win=false;
}
public void setWin(boolean win)
{
this.win=win;
}
public boolean getWin()
{
return this.win;
}
public void setPlayerName(String name)
{
this.name=name;
}
public void setTurn(int turn)
{
this.turn=turn;
}
public int getTurn()
{
return this.turn;
}
public void addScore(int score)
{
this.score+=score;
}
public String getName()
{
return this.name;
}
public int getScore(){
return this.score;
}
public void resetFoulCount() {
this.foul_count = 0;
}
public void incrementFoulCount() {
this.foul_count++;
}
public int getFoulCount()
{
return this.foul_count;
}
public void resetConsecutiveMisses() {
this.consecutive_misses = 0;
}
public void incrementConsecutiveMisses() {
this.consecutive_misses++;
}
public int getConsecutiveMisses()
{
return this.consecutive_misses;
}
public int compareTo(player comparePlayer)
{
int compareScore=((player) comparePlayer).getScore();
return compareScore-this.score;
}
}
Qyouu
相关分类