@AdelaTort
Java Senior Developer en Edreams
Colaboradora del Barcelona Java Users Group
Seguidora del movimiento de la artesanía del software y aspirante a Software Craftman
@AdelaTort
https://www.linkedin.com/in/adelatort
adela.tort@gmail.com
public class ShoppingCart{
private List<Product> products;
public Double getTotalPrice(){
Double p=0.0;
for(Product prod: products){
p=p+prod.getPrice();
}
return p;
}
}
public class ShoppingCart{
private List<Product> products;
public Double getTotalPrice(){
Double totalPrice=0.0;
for(Product product: products){
totalPrice=totalPrice+product.getPrice();
}
return totalPrice;
}
}
public class Product {
public String name;
}
public class Product {
private String name;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
}
public Double calculatePrice(){
Double totalPrice = 0.0;
for(Product p : products){
totalPrice = totalPrice + p;
}
if(totalPrice > 100) {
totalPrice = totalPrice - 10;
}
return totalPrice;
}
public Double calculatePrice(){
Double totalPrice = calculateProductsPrice();
return applyDiscounts(totalPrice);
}
private Double calculateProductsPrice(){
Double totalPrice = 0.0;
for(Product p : products){
totalPrice = totalPrice + p;
}
return totalPrice;
}
private Double applyDiscounts(Double price){
Double priceWithDiscounts=price;
if(price> 100) {
priceWithDiscounts=priceWithDiscounts- 10;
}
return priceWithDiscounts;
}
if (date.before (SUMMER_START) || date.after(SUMMER_END))
charge = quantity * _winterRate + _winterServiceCharge;
else charge = quantity * _summerRate;
if (notSummer(date))
charge = winterCharge(quantity);
else charge = summerCharge (quantity);
public Float getArea() {
switch (type) {
case RECTANGLE:
return getWidth()*getHeight();
case CIRCLE:
return getPi()*getRadius()*getRadius();
case TRIANGLE:
return (getBase()*getHeight())/2;
}
throw new RuntimeException ("Unexpected type");
}
public Integer getAmount(int quantity){
if(quantity > numAvailable){
return -1;
}
else{
return quantity * price;
}
}
public Integer getAmount(int quantity) throws UnavailableProductException {
if(quantity > numAvailable){
throw new UnavailableProductException();
}
else{
return quantity * price;
}
}
Refactoring: Improving the
Design of Existing Code
by Martin Fowler