Skip to content

Instantly share code, notes, and snippets.

@nettofarah
Created May 12, 2011 03:48
Show Gist options
  • Save nettofarah/967894 to your computer and use it in GitHub Desktop.
Save nettofarah/967894 to your computer and use it in GitHub Desktop.
Service Obsession
public class Product {
private String name;
private float price;
public Product(String name, float price){
this.name = name;
this.price = price;
}
// ... getters and setters
}
public class ProductService{
public void updatePriceWithDiscount(Product product, float rate){
float newPrice = product.getPrice() - product.getPrice() / rate;
product.setPrice(newPrice);
}
//... other USELESS methods
}
public class ProductController{
//...
//Maps some url or stuff like that
public void updatePriceWithDiscount(Product product, float rate){
productService.updatePriceWithDiscount(product, rate);
//do some other thing with the response..
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment