title: Kotlin top-levels functions vs object function
body: <p>I have static function which is limited to some context eg only for docs. There are 2 alternative ways to define it as top-level function or function in an object.</p>
  
  <p>1.</p>
  
  <pre><code>package com.armsoft.mtrade.data.pref
  
  import com.armsoft.mtrade.App
  import com.armsoft.mtrade.domain.model.DocSaveType
  
  object DocPrefManager {
      private const val DOC_PREF = "DOC_PREF"
  
      private const val KEY_ORDER_SAVE_TYPE = "KEY_ORDER_SAVE_TYPE"
  
      @JvmStatic
      fun setOrderSaveType(orderSaveType: DocSaveType) {
          val context = App.getContext()
          val sharedPreferences = context.getSharedPreferences(DOC_PREF, 0)
          val editor = sharedPreferences.edit()
          editor.putString(KEY_ORDER_SAVE_TYPE, orderSaveType.getCode())
          editor.commit()
      }
  }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>package com.armsoft.mtrade.data.pref
  
  import com.armsoft.mtrade.App
  import com.armsoft.mtrade.domain.model.DocSaveType
  
  fun setOrderSaveType(orderSaveType: DocSaveType) {
      val context = App.getContext()
      val sharedPreferences = context.getSharedPreferences(DocPrefManager.DOC_PREF, 0)
      val editor = sharedPreferences.edit()
      editor.putString(DocPrefManager.KEY_ORDER_SAVE_TYPE, orderSaveType.getCode())
      editor.commit()
  }
  </code></pre>
  
  <p>The advantage of top-level function that it is not wrapped in an object and disadvantage that it can be accessed from everywhere without class name prefix. Are there advantages or disadvantages or best practice for such cases? </p>