lundi 14 septembre 2020

Util class requiring a start method before it can do its tasks

   public class SomeUtil {

   private static someClient someClient;

   private SomeUtil() {
   }

   public static void createSomeUtil(final String path,
                                       final String endPointUrl) {
       someClient = new Client(path, endPointUrl)
   }

   public static Record fetchRecord(final String Id) {
       return someClient.fetchRecord();
   }

   public static void updateStatus(final String Id, final String status) {
       someClient.updateStatus(Id, status);
   }
}

This is in a library package and this requires two parameters to create "someClient" which will then allow it to do its work. I'm calling this from a main package and it has the parameters to pass in its config file. When I call this class from main method, I need to call createSomeUtil before I can call its method. I don't like this approach much as there's no visual trace for the caller that this createSomeUtil has to be called for the rest of the methods to work (As all of these are separate public static methods). Is this approach okay? OR is there a better way to achieve this? The constraint is that the values of "path" and "endPointUrl" are decided by the caller.

Aucun commentaire:

Enregistrer un commentaire