Click here to Skip to main content
15,359,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 beginner to oop 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 provide steps for refactoring thanks.

so the code stubs below do
* The method `alpha()` returns an instance of Object based on a `Status` and DayOfWeek.
* Either of the classes `Beta` and `Gamma` can be used to handle a `Status` of Slight, Low or Medium and there are many other potential related types than can handle similar requests.
* Depending on the DayOfWeek the remaining enumerations of `Status` are handled by instances of `Delta`, `Zeta` and `Epsilon` and an unbounded number of related types. `Delta`, `Zeta` and `Epsilon` can be orchestrated together to create complex types.


What I have tried:

Java
Class Alpha
<pre lang="java">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**
```
Java
public class Beta {
	public String beta() {
		return "Executing " + this.getClass().getName();
	}


}
```
**Class Gamma**
```
Java
public class Gamma {
	public String gamma() {
		return "Executing " + this.getClass().getName();
	}
}

```
**Class Zeta**
```
Java
public class Zeta {
	public int zeta(String value) {
		return Integer.parseInt(value) + 7;
	}
}

```
**Class Delta**
```
Java
public class Delta {
	public int delta(String value) {
		return value.hashCode();
	}
}

```
**Class Epsilon**
```
Java
public class Epsilon {
	public int epsilon(String value) {
		return value.length();
	}
}

```
**Enum Status**
```
Java
public enum Status {
	Slight,
	Low,
	Medium,
	High,
	Extreme;
}

```
Posted
Updated 7-Nov-20 21:46pm

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900