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 and Refactoring #2

Open
carana08 opened this issue Aug 12, 2023 · 0 comments
Open

Code Smell and Refactoring #2

carana08 opened this issue Aug 12, 2023 · 0 comments

Comments

@carana08
Copy link

carana08 commented Aug 12, 2023

Hello, for student reasons I have looked for parts of your code where there may code smells and refactoring techniques can be applied.
In the CartItem and Cart classes you might get the stink of Inappropriate Intimacy because the getTotalPrice method is implemented in Cart but uses mostly information from CartItem

public double getTotalPrice() {
totalPrice = 0;
cartItems.forEach((cartItem) -> {
totalPrice += cartItem.getPrice();
});
return totalPrice;
}

To fix this bad smell you can apply the move method technique with it the getTotalPrice method you could work directly in CartItem with the price of the Item and the amount it has.
Here is an example of a possible implementation:
image
image

@carana08 carana08 changed the title Smell Code and Refactoring Code Smell and Refactoring Aug 12, 2023
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