I am doing some work to refactor a class. It currently a 'God class' and contains all different logic/operations solely in that class. One of my solutions is to extract all different parts of logic to their own classes. This will result in an 'Orchestrator' class calling all separate classes to execute logic. Example:
public class TripOrchestrator {
public Trip build(TripInformation information) {
final TripFee tripFee = new TripFeeBuilder(information.getFee());
final TripTiming tripTiming = new TripTimingBuilder(information.getTripTiming());
final TripSettings tripSettings = new TripSettingsBuilder(information.getSettings());
final TripNotification tripNotification = new TripNotification(information.getNotification);
return new Trip(tripFee, tripTiming, tripSettings, tripNotification);
}
}
Before this refactoring, all of this logic was placed into one 'God class' without any builder classes.
My Question
Firstly is this a reasonable approach to go with for a problem such as this? Secondly, is it bad that I am violating DIP? For example,
final TripFee tripFee = new TripFeeBuilder(information.getFee());
TripFee object is a concrete class, so is TripFeeBuilder. All of these implementations are 'concrete' and not 'abstracted' to their interface. My thought on why this MAY be okay is that all of these builders and classes are very stable. It is rare that logic/functionality will change and if there is a change, it will be a very minor one.
DIP states that the above line should be:
final ITripFee tripFee = new TripFeeBuilder(information.getFee());
With 'ITripFee' being an interface and having TripFeeBuilder be one of the possible implementations. But like I stated, there most likely won't be another implementation of TripFee.
Would love thoughts/opinions about this. I have experience in Java but still a novice in design. Thanks.
TripandTripInformationshare such a lot of information - are there actually differences between them?