Home » Core Java » Design Patterns » decorator


Java EE 6 Decorators advanced usage

The example we’ll use is a Social media feed processor. So I have created an interface:   public interface SocialFeedProcessor { Feed process(String feed); } and provided 2 implementations, twitter and google+   public class TwitterFeedProcessor implements SocialFeedProcessor{ @Override public Feed process(String feed) { System.out.println("processing this twitter feed"); // processing logics return new Feed(feed); } } public class GooglePlusFeedProcessor implements ...

Read More »

Decorating classes at injection time with Java EE 6

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 »