UML & Programming Martin Fowler
Content Class Diagrams to Java Code Interaction Diagrams
Class diagrams for Order
Specification Perspective class Order{ public Order (Customer customer); public Date getReceived(); public void setReceived(Date arg); public String getNumber(); public Customer getCustmoer(); public void setCustomer(Customer arg); public Enumeration getOrderLines(); public void addOrderLines(OrderLine arg); public void removeOrderLine(OrderLine arg); public void price(); } class OrderLine{ public OrderLine(int quantity, Product product); public int getQuantity(); public Money getPrice(); public Product getProduct();
Implementation Perspective class Order{ public Order(Customer customer); private Customer _customer; private Vector _orderLines; private Date _recevied; private String _number; public void price(); } class OrderLine{ public OrderLine(int quantity, Product product); private int _quantity; private Money _price; private Product _product;
Constraints
Implementing a Constraint class Order{ boolean isValid{ if (getCustomer.getCreditRating.equals(CreditRating.poor())) return isPrepaid(); else return true; } void assertInvariant(){ if(IS_DEBUGGING) if(!isValid()) throw new RuntimeExcetption( “Order Object not valid”);