i am required to provide a redesign and refactoring of the classes that provides maximum reusability, extensibility and eliminates as many dependencies as possible in the class Alpha. i am free to change any of the classes in any way i wish, including renaming, changing method signatures and deriving new types. but i am newbie to this and dont know where to start and how it should be done and what the result will be like and why? so can anyone please help me with this thanks.
Class Alpha
import java.time.DayOfWeek;
import java.time.LocalDate;
public class Alpha {
private Beta beta = new Beta();
private Gamma gamma = new Gamma();
private Delta delta = new Delta();
private Epsilon epsilon = new Epsilon();
private Zeta zeta = new Zeta();
public Object alpha(Status s) {
//Beta and Gamma only deal with Status values of Slight, Low and Medium
if (s == Status.Slight || s == Status.Low) {
return beta.beta();
}else if (s == Status.Medium) {
return gamma.gamma();
}else {
//Delta, Epsilon and Zeta handle more complex situations
DayOfWeek day = LocalDate.now().getDayOfWeek();
return switch (day) {
case MONDAY, TUESDAY -> delta.delta(day.name());
case WEDNESDAY, THURSDAY -> epsilon.epsilon(day.name());
case FRIDAY -> zeta.zeta(day.name());
case SATURDAY -> Integer.valueOf((delta.delta(day.name()) + epsilon.epsilon(day.name())));
case SUNDAY -> Integer.valueOf((epsilon.epsilon(day.name()) + zeta.zeta(day.name())));
};
}
}
}
Class Beta
public class Beta {
public String beta() {
return "Executing " + this.getClass().getName();
}
}
Class Gamma
public class Gamma {
public String gamma() {
return "Executing " + this.getClass().getName();
}
}
Class Zeta
public class Zeta {
public int zeta(String value) {
return Integer.parseInt(value) + 7;
}
}
Class Delta
public class Delta {
public int delta(String value) {
return value.hashCode();
}
}
Class Epsilon
public class Epsilon {
public int epsilon(String value) {
return value.length();
}
}
Enum Status
public enum Status {
Slight,
Low,
Medium,
High,
Extreme;
}
Aucun commentaire:
Enregistrer un commentaire