Note that there are some explanatory texts on larger screens.

plurals
  1. POStrategy pattern for billing models that use different data for the calculation?
    primarykey
    data
    text
    <p>We have an invoice model that bills clients in a few different ways. For the sake of brevity, I'm going to focus on two: cost per impression and cost per phone inquiry. My thought was to implement these (and the rest) as strategies and then dynamically mix them into the invoice class. </p> <p>This seems appropriate because there are different sources of information used to determine the number of impressions/calls. This could be encapsulated in the strategy, while keeping the basic formula in the <code>Invoice</code> class.</p> <p>The calculation for cost per impression is simple: <code>num impressions X cost per impression</code>.</p> <p>The calculation for phone inquiries is a little more complicated: <code>num calls X cost per call</code>.</p> <pre><code>class Invoice def self.strategy self.class_eval &lt;&lt;-EOS include #{billing_type} EOS end def invoice_amount # this will used the module mixed in above self.rate * calculate_impressions end end </code></pre> <p>Then, the modules could be:</p> <pre><code>module PerImpressionCalculation def calculate_impressions # get the number of impessions from source a... end end module PerInquiryCalcuation def calculate_impressions # get the number of impessions from source b... end end </code></pre> <p>However, whether a call counts or not is based on the length of the call and this varies from model to model. Thus, when I'm searching through the phone logs I need to have this value. </p> <p>My question is where does this value get stored? I could create a strategy for invoices that are based on 10 second calls and a separate one for 30 second ones, but that seems wasteful. If a deal came in that wants the threshold to be 15 seconds, I need to write a new strategy. What is the best design choice to solve this issue?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload