亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么這被認為是不安全的?

為什么這被認為是不安全的?

鳳凰求蠱 2023-06-28 15:45:41
最近,我用 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;      }}
查看完整描述

1 回答

?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

類不應該暴露它的內部結構。通過暴露其內部結構,它違反了許多法律,例如德米特法則,其他類別可以利用這種情況并設置他們想要的任何分數。

查看完整回答
反對 回復 2023-06-28
  • 1 回答
  • 0 關注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號