Approach 2: Instance Methods
- The ProfileFetcher can be constructed and passed to TradeCalculator
- When calculating trades, our tool calls the instance method
public class TradeCalculator {
// Set this.profileFetcher in TradeCalculator's constructor
public Something calculateTrades(String userId) {
ProfileData data = this.profileFetcher.fetchProfile(userId)
// Do math !
}
}
public class ProfileFetcher {
public ProfileData fetchProfile(String userId) {
// Complex SQL?
return userProfile;
}
}
22 / 31