Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The empty Record class and the free-floating function that (generally) applies to an individual Record is a hint that you haven't designed your class properly.</p> <pre><code>class Record( object ): """Assuming rtda and pnl must exist.""" def __init__( self ): self.da= 0 self.rt= 0 self.rtda= 0 # or whatever self.pnl= None # self.sink = None # Not clear what this is def setPnl( self, node_prices ): # fill RT and DA prices from the hash retrieved above # calculate dependent values: RT-DA and PNL </code></pre> <p>Now, your <code>calculate_pnl( records, node_prices )</code> is simpler and uses the object properly.</p> <pre><code>def calculate_pnl( records, node_prices ): for record in records: record.setPnl( node_prices ) </code></pre> <p>The point isn't to trivially refactor the code in small ways.</p> <p>The point is this: <strong>A Class Encapsulates Responsibility</strong>.</p> <p>Yes, an empty-looking class <em>is</em> usually a problem. It means the responsibilities are scattered somewhere else.</p> <p>A similar analysis holds for the collection of records. This is more than a simple list, since the collection -- as a whole -- has operations it performs.</p> <p>The "Request-Transform-Render" isn't quite right. You have a Model (the Record class). Instances of the Model get built (possibly because of a Request.) The Model objects are responsible for their own state transformations and updates. Perhaps they get displayed (or rendered) by some object that examines their state.</p> <p>It's that "Transform" step that often violates good design by scattering responsibility all over the place. "Transform" is a hold-over from non-object design, where responsibility was a nebulous concept.</p>
 

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