title: Choosing between Trait and Object
body: <p>I was trying to look into <code>trait</code> and <code>object</code> in scala when it seems like we can use trait and object to do a similar task.</p>
  
  <p>What should be the guiding principles on when to use <code>trait</code> and when to use <code>object</code>?</p>
  
  <p>Edit:
  As many of you are asking for an example</p>
  
  <pre><code>object PercentileStats {
   def addPercentile(df: DataFrame): DataFrame // implementation
  }
  
  trait PercentileStats {
   def addPercentile(df: DataFrame): DataFrame // implementation
  }
  </code></pre>
  
  <p>There is a Process class which can use the object</p>
  
  <pre><code>object Process {
   def doSomething(df: DataFrame): DataFrame {
     PercentileStats.addPercentile(df)
   }
  }
  </code></pre>
  
  <p>We can also make it use the trait</p>
  
  <pre><code>object Process with PercentileStats {
   def doSomething(df: DataFrame): DataFrame {
    addPercentile(df)
   }
  }
  </code></pre>