1

For example, say I have a service that kicks off some operation, such as running a cron-job. Then, it returns whether it not it was successful.

The code might look something like

 var service = new MetricSyncWakeJob(...);
 var jobStarted = service.performSyncJob();

 if(jobStarted) {
     notificationService.notifySuccess("Operation was successful.");
 } else {
     notificationService.notifySuccess("Operation was NOT a success.");   
 }

Is it ever worth wrapping up such code or this something akin to eager-abstraction? If so, how would you do this this? What a Facade work here?

i.e: UserInteractiveMetricSyncWakeJob which can kick off the job and fire the message automatically?

It's not the job of the service to kick off this message -- otherwise, it could just be put there. I guess the class could look like this...

class UserInteractiveMetricSyncWakeJob
  UserInteractiveMetricSyncWakeJob(INotificationService notifcationService, MetricSyncWakeJob wakeJob)

It seems overkill to do this -- yet, copy & pasting the same "handle this response" code seems bad, too.

1

The simplest method i can think (depending on the language your using) would be to set up a class with a static map variable as an atrribute, you can then call store your error message and any other reused strings as the value and a shorthand code for the key. Then every time you require that error message you can access it through the map. This has the added benefit that if you want to reword the error message or have alternate messages you can easily make such changes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.