Home » design patterns » Page 4

Tag Archives: design patterns

Decorating classes at injection time with Java EE 6

Bipartite Graph

Let’s say you have a ticket service that lets you order tickets for a certain event. The TicketService handles the registration etc, but we want to add catering. We don’t see this as part of the ticket ordering logic, so we created a decorator. The decorator will call the TicketService and add catering for the number of tickets. The interface: ...

Read More »

Implement a shopping cart using the Strategy Pattern

Bipartite Graph

First a definition: in the simplest terms, you can define the Strategy Pattern as telling an object to do a job and to do it using ANOTHER object. To clarify this further I’m going to redesign the ShoppingCart slightly, by giving it a pay()* method: public class ShoppingCart { private final List<Item> items; public ShoppingCart() { items = new ArrayList<Item>(); ...

Read More »