Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Smell: Data Clumps in "BillyBurger" #4

Open
DJavierReyesM opened this issue Jan 16, 2021 · 0 comments
Open

Code Smell: Data Clumps in "BillyBurger" #4

DJavierReyesM opened this issue Jan 16, 2021 · 0 comments

Comments

@DJavierReyesM
Copy link

DJavierReyesM commented Jan 16, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant