Code Smell of the Week, Design Patterns

Code Smell of the Week : Broken Encapsulation

Lets take a scenario of a customer placing an order on an ecommerce website. The order may comprise of several products. This order once placed cannot be changed but it will need to be displayed to the customer

public class Order
 private List<Product> products;
 //other variables, methods and constructors

 public List getProducts()
  return products;

 public void setProducts(
    List<Products> products)
//sample usage of Order

However comparing the requirement to the code it is evident that something is wrong.

Continue reading