title: Kotlin Delegation how to access class properties from delegate object
body: <p>I'm trying to split some work from a giant class to provide more readability. Firstly I looked into Extension but seems like it is just creating some static functions, then delegate pattern came into my eyes.</p>
  
  <p>The below code looks all right, and delegate works as if part of EnhancedProducer class.
  But there is one problem that blocking me though, I don't quite get how to access the service property of EnhancedProcuder class from delegate. In my real code, there are some cases that both the original class and delegate class need to use the service variable at the same time, so I don't know if there is a way to do it. </p>
  
  <p>I do understand we can probably inject service instance into both of them but I still want to find out if there is a more elegant way to makes delegate fit into EnhancedProducer class more naturally.</p>
  
  <pre><code>interface Producer {
  
      fun produce()
  }
  
  class ProducerImpl : Producer {
  
      override fun produce() {
         // service.doSomething() how to access service here
         println( "ProducerImpl")
      } 
  }
  
  class EnhancedProducer(private val delegate: Producer) : Producer by delegate {
  
      // how to share this with delegate 
      //private val service = Service() 
  
      fun test() {
          produce()
      }
  }
  
  fun main() {
      val producer = EnhancedProducer(ProducerImpl())
      producer.test()
  }
  </code></pre>