We have an account model that pays customers in several ways. For brevity, I’m going to focus on two: cost per impression and cost per phone request. My thought was to implement these (and the rest) as strategies, and then dynamically mix them with the invoice class.
This seems appropriate because there are different sources of information used to determine the number of impressions / calls. This can be encapsulated in a strategy while keeping the basic formula in the class Invoice.
Calculating the cost of the show is simple: num impressions X cost per impression.
Calculation of telephone inquiries a little more complicated: num calls X cost per call.
class Invoice
def self.strategy
self.class_eval <<-EOS
include #{billing_type}
EOS
end
def invoice_amount
self.rate * calculate_impressions
end
end
Then the modules can be:
module PerImpressionCalculation
def calculate_impressions
end
end
module PerInquiryCalcuation
def calculate_impressions
end
end
, , , , . , , .
, ? -, 10- , 30-, . , , 15 , . ?