I learnt everywhere that using if statement is a bad practice when it's possible to avoid them . I'm trying to learn how to make clean code, it seems also that some design patterns could be helpful so I'm wondering if it's possible to refactor this piece of code in order to remove if statement from, here is the code desmonstrating this:
public boolean print(Job aJob){
if (isAvailable()){
currentJob=aJob;
aJob.setPrinter(this);
aJob.setState(Job.PRINTING);
return true;
}
System.err.println("Error");
return false;
}
public boolean printingCompleted(){
if (isPrinting()){
currentJob.setPrinter(null);
currentJob.setState(Job.COMPLETED);
currentJob=null;
return true;
}
System.err.println("Error");
return false;
}
public boolean isAvailable(){
return on && currentJob==null;
}
public boolean isPrinting(){
return on && currentJob!=null;
}
Aucun commentaire:
Enregistrer un commentaire