You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello again. I hope you're doing fine. I was checking your code again and I come up with something. In the Hamburger class there are several related fields that are repeated over and over again, such as the name of the add-on and its price. generate a kind of duplicate code, for example, the methods to define the add-ons are repeated for each add-on name-price pairs. In turn, these groups of variables always act together and without one, the other would be meaningless for the class. So, you can refactor your code by usin Extract Class. Since these groups of variables are already contained within a class, it would facilitate the understanding of the code and its organization by not having the variables dispersed throughout the class. In turn, organizing them within a class allows the size of the code to be reduced and even, if you want to perform some type of operation with groups of variables, this will be easier since the variables now belong to a class as such. Once the class is extracted, the variables are replaced by calls to the objects of the HamburgerAdditional class. Code for the new class:
public class HamburgerAdditional {
public String name;
public double price;
public HamburgerAdditional(String name, double price) {
this.name=name;
this.price=price;
}
public String getName() {
return this.name;
}
public double getPrice() {
return this.price;
}
public void setName(String name){
this.name=name;
}
public void setPrice(double price) {
this.price=price;
}
public String toString() {
return "Adittional: "+name+" - "+price;
}
}
Have a nice day!
The text was updated successfully, but these errors were encountered:
Hello again. I hope you're doing fine. I was checking your code again and I come up with something. In the Hamburger class there are several related fields that are repeated over and over again, such as the name of the add-on and its price. generate a kind of duplicate code, for example, the methods to define the add-ons are repeated for each add-on name-price pairs. In turn, these groups of variables always act together and without one, the other would be meaningless for the class. So, you can refactor your code by usin Extract Class. Since these groups of variables are already contained within a class, it would facilitate the understanding of the code and its organization by not having the variables dispersed throughout the class. In turn, organizing them within a class allows the size of the code to be reduced and even, if you want to perform some type of operation with groups of variables, this will be easier since the variables now belong to a class as such. Once the class is extracted, the variables are replaced by calls to the objects of the HamburgerAdditional class. Code for the new class:
}
Have a nice day!
The text was updated successfully, but these errors were encountered: