Notification Service: Message delivery service-NOT!
15 November 2008OK, now I am having second thoughts. After putting together the DeliveryService interface, I sat down to see about implementing it, and I started thinking that maybe I don’t even want to go this route at all. Maybe, instead of handing the message and delivery method off to a service that just passes the message on to a MessageCourier appropriate for the delivery method, I should just have a MessageCourierFactory that constructs the appropriate courier as requested. In actual use, that would only be a slight alteration of the approach that I had originally envisioned:
DeliveryService.deliverMessage(deliveryMethod, addresses, titleSubject, contentType, body);
… to something more like this:
MessageCourier courier = MessageCourierFactory.getMessageCourier(deliveryMethod); courier.deliverMessage(addresses, titleSubject, contentType, body);
Maybe it’s just six of one and half a dozen of the other, but I’m starting to think I like the second approach a little better. I don’t know … maybe not. Or maybe I’ll do both! Hmmm …
In fact, if I do both, then the DeliveryServiceImpl would simply look like this:
package org.restafarian.notify.service;
import java.util.List;
import org.restafarian.notify.beans.MessageAddress;
/**
* <p>This class implements the DeliveryService interface.</p>
*/
public class DeliveryServiceImpl implements DeliveryService {
/**
* <p>Delivers the message to the specified recipient(s) using the
* specified delivery method.</p>
*
* @param deliveryMethod the method to be used to deliver the message
* @param addresses an array of "address" objects containing the
* implementation-specific addresses required for successful delivery of
* the message
* @param titleSubject an optional subject and/or title of the message to
* be delivered
* @param contentType the mime type of the message body
* @param body the text of the message to be delivered
*/
public void deliverMessage(String deliveryMethod, MessageAddress[] addresses,
String titleSubject, String contentType, String body) {
MessageCourier courier = MessageCourierFactory.getMessageCourier(deliveryMethod);
courier.deliverMessage(addresses, titleSubject, contentType, body);
}
}
But then, that seems rather pointless! Why even have the DeliveryService at all if it’s just for two lines of code?
I guess I’ll just have to start playing around with it and see what feels right as I put it all together …
Leave a reply
You must be logged in to post a comment.





