-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
This issue may produce potential bugs.
If you have the following code:
(As seen in GameState, Entity, Enemy, etc.)
public void setCurrentLevel(int currentLevel) {
this.currentLevel = currentLevel;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public List<Enemy> getEnemies() {
return enemies;
}
public void setEnemies(List<Enemy> enemies) {
this.enemies = enemies;
}
public List<Tower> getAvailableTowers() {
return availableTowers;
}
public List<Tower> getDeployedTowers() {
return deployedTowers;
}
public List<Point> getCurrentWaypoints() {
return currentWaypoints;
}
public void setCurrentWaypoints(List<Point> currentWaypoints) {
this.currentWaypoints = currentWaypoints;
}
public int[][] getGrid() {
return grid;
}
public int getMoney() {
return money;
}
public int getLife() {
return life;
}
public void setLife(int life) {
this.life = life;
}
public void setMoney(int money) {
this.money = money;
}
public float getWaveSpawnTime() {
return waveSpawnTime;
}You could have used public attribute instead. It would have been easier.
The reason why you make your object attributes private is because you want to provide your own interfaces for modifying / manipulating the said attributes.
public void setLife(int life) {
this.life = life;
}Could have been
public void receiveDamage(Enemy enemy) {
this.life -= enemy.getDamage();
}Which is better than allowing the developer to set the value of Life immediately. It provides less areas for bugs.
Reactions are currently unavailable