title: Object condition in multiple places/repeated code (DRY)
body: <p>This is a fundamental application design question I’ve struggled with and flip-flopped on for years. We have a legacy webapp that doesn't really have a solid ORM, if that tidbit might influence your answer. To abstract my question let’s say we have a class Car, and a corresponding table in our database named car. Car has a few properties: color, weight, year, maxspeed    These properties directly correspond to columns in the db table.</p>
  
  <p>In our application, we define the car as “classic old” if year is &lt; 1960 and color = black. And in many places within our app knowing whether the car is "classic old" is extremely important (maybe we’re running a very illogical insurance agency which gives steep discounts and other perks to cars which are “classic old”).</p>
  
  <p>All over our application, we do things like:</p>
  
  <p>--list all classic old cars</p>
  
  <p>--give the current user a discount if their car is classic old</p>
  
  <p>--list all classic old cars with max speed > 100 miles per hour</p>
  
  <p>--email the current user if their car is classic old and weights more than 1000 pounds</p>
  
  <p>What is the best way to go about this? We have a legacy application that does this in some places:</p>
  
  <pre><code>getOldClassicCars()
  
  select * where year &lt; 1960 and color = black
  </code></pre>
  
  <p>and in other places:</p>
  
  <pre><code>cararray = getAllCars();
  
  for each car in cararray
        if car.year &lt; 1960 and car.color = black
                 oldcararray = car.add()
  </code></pre>
  
  <p>The point being that this very important, fundamental piece of our application – is the car classic old – is “hardcoded” as <code>year &lt; 1960 and color = black</code> in many places. Sometimes in SQL, sometimes in application code, etc. Obviously that is not good, but as we’ve refactored things I’m not sure we’re refactoring things the best way we can.</p>