I have never done this, but for the usecase that you have mentioned, would the following work?
class Xyz { private Type type; private RetType type1MethodName(params) { // Do Whatever } private RetType type2MethodName(params) { // Do Whatever } public Xyz(type) { this.type = type; } public RetType methodName(params) { switch(type) { type1: return type1MethodName(params); type2: return type2MethodName(params); } } public enum Type { type1; type2; } }
I have never done this, but for the usecase that you have mentioned, would the following work?
And then when we want to pass methods according to types, we can just instantiate the class with a proper type and pass it.