samedi 14 septembre 2019

Implement Method According To Boolean Type

I have a code block like below:

public Interface INormalClass{
   void call();
}

public class NormalClass implements INormalClass{
   void call(){
     ....operations...
   }
}

public Interface IDailyClass{
   void call();
}

public class DailyClass implements IDailyClass{
   void call(){
     ....operations...
   }
}

Then I call them from main service like that;

public void call(boolean isDaily){
  if(isDaily){
     dailyClass.call();
  }
  else{
    normalClass.call();
}
}

Is there a way to escape from isDaily check in above code block?

Aucun commentaire:

Enregistrer un commentaire