https://kotlinlang.org logo
Title
a

ankit.sharma

12/02/2018, 9:17 PM
Heya everyone! 👋 I’m a noob to kotlin and had this question. I’m trying to build a retrofit service class in kotlin and saw two approaches and not sure which one is better. 1. In the
RetrofitApi.kt
interface, define a companion object which returns a service object. 2. Define a separate class and instantiate the object in
init {}
. Is there a recommended way of doing things on android and what are the pros and cons of each approach? Thanks!
g

gildor

12/03/2018, 2:09 AM
Up to you. I would say that first approach is bad because coupling declaration with implementation initialization in constructor of another class also doesn’t look correct for me, I would better write some factory of services But it depends on your use case of course, and Kotlin implementation is not something very different from Java
👍 1