title: In Scala is there a way to reference the Companion Object from within an instance of a Case Class?
body: <p>In my specific case I have a (growing) library of case classes with a base trait (<code>TKModel</code>) </p>
  
  <p>Then I have an abstract class (<code>TKModelFactory[T &lt;: TKModel]</code>) which is extended by all companion objects. </p>
  
  <p>So my companion objects all inherently know the type ('T') of "answers" they need to provide as well as the type of objects they "normally" accept for commonly implemented methods. (If I get lazy and cut and paste chunks of code to search and destroy this save my bacon a lot!) I do see warnings on the Internet at large however that any form of <code>CompanionObject.method(caseClassInstance: CaseClass)</code> is rife with "code smell" however. Not sure if they actually apply to Scala or not?  </p>
  
  <p>There does not however seem to be any way to declare anything in the abstract case class (<code>TKModel</code>) that would refer to (at runtime) the proper companion object for a particular instance of a case class. <em>This results in my having to write (and edit) a few method calls that I want standard in each and every case class.</em></p>
  
  <p><code>case class Track(id: Long, name: String, statusID: Long) extends TKModel</code></p>
  
  <p><code>object Track extends TKModelFactory[Track]</code></p>
  
  <p>How would I write something in <code>TKModel</code> such that <code>new Track(1, "x", 1).someMethod()</code> could actually call <code>Track.objectMethod()</code> </p>
  
  <p>Yes I can write <code>val CO = MyCompanionObject</code> along with something like  <code>implicit val CO: ???</code> in the <code>TKModel</code> abstract class and make all the calls hang off of that value. Trying to find any incantation that makes the compiler happy for that however seems to be mission impossible. And since I can't declare that I can't reference it in any placeholder methods in the abstract class either. </p>
  
  <p>Is there a more elegant way to simply get a reference to a case classes companion object? </p>
  
  <p>My specific question, as the above has been asked before (but not yet answered it seems), is there a way to handle the inheritance of both the companion object and the case classes and find the reference such that I can code common method calls in the abstract class? </p>
  
  <p>Or is there a completely different and better model? </p>