mardi 1 mars 2016

Design patterns: helper class in front of Factory

Say, I've got a NotificationServiceFactory class with getService(Enum notificationType) method.

But in most cases there is just notificationId as the input, without notificationType.

So, i have to invoke some sort of Helper class to retrieve Notification from database by id, than run getService(Enum notificationType) and finally invoke desired method on obtained service.

Pseudocode:

class NotificationController() {

    private NotificationServiceHelper helper;

    void processNotification(Long notificationId) {
        helper.processNotification(notificationId);
    }   
}

class NotificationServiceHelper() {

    private NotificationServiceFactory factory;
    private NotificationRepository repository;

    void processNotification(Long notificationId) {
        Notification notification = repository.find(notificationId);
        factory.getService(notification.getType()).processNotification(notification);
    }
}

What is this NotificationServiceHelper class? Facade? Adapter?

Is that a bad practice, or just a standard approach?

Aucun commentaire:

Enregistrer un commentaire