I have a codebase that was originally created with a number of different options that allow you to get the code to perform the same process in a slightly different way, like this:
public class MainFunction {
public void main(String option){
if (option.equals("vanilla mode")){
this.firstFunction();
}else{
this.differentVersionOfFirstFunction();
}
this.secondFunction();
}
public void firstFunction(){
//First functions code
}
public void secondFunction(){
//Second functions code
}
public void differentVersionOfFirstFunction(){
// different code from First functions code that produces the same type of end result using a slightly different method
}
}
This has gotten gradually more and more complex as various different options are added and the code becomes increasingly convoluted.
To resolve this I had originally planned to create a Parent object, that could then have children with subtlety different variations on their Parents methods when needed. The problem is that I understand that this would violate the Liskov Substitution Principle and indeed I may have children that should be sharing the same method that may not be present in their parent.
So I am left with having the different methods in the same class object, doing the same job in slightly different ways.
public class MainFunction {
public void main1(){
this.firstFunction();
this.secondFunction();
}
public void main2(){
this.differentVersionOfFirstFunction();
this.secondFunction();
}
public void firstFunction(){
//First functions code
}
public void secondFunction(){
//Second functions code
}
public void differentVersionOfFirstFunction(){
// different code from First functions code that produces the same type of end result using a slightly different method
}
}
I suppose I could create a separate Utility class to hold all my various functions, but I was not sure if there was a more elegant solution?