---
# System prepended metadata

title: Untitled

---

```kotlin=

// interfaceを利用する例
class DisplayImagesAdapter(
    private val listener: DisplayRankingImagesViewHolder.Listener,
) {
    
    class DisplayRankingImagesViewHolder(private val listener: Listener) {
        private val recyclerView
        
        init {
            recyclerView.setOnScrolled {
                listener.loadMoreRanking()
            }
        }
        
        fun bind() {}
        
        interface Listener {
            fun loadMoreRanking()
        }
    }
    
    override fun onCreateViewHolder() {
        DisplayRankingImagesViewHolder(listener)
    }
}

class MainActivity : DisplayImagesAdapter.DisplayRankingImagesViewHolder.Listener {
    
    override fun loadMoreRanking() {
        viewModel.loadMoreRanking()
    }
    
    override fun onCreate() {
        val adapter = DisplayImagesAdapter(this)
    }
}

// Callbackを利用する例
class DisplayImagesAdapter(
    private val loadMoreRanking: () -> Unit
) {
    
    class DisplayRankingImagesViewHolder(
        private val loadMoreRanking: () -> Unit
    ) {
        private val recyclerView
        
        init {
            recyclerView.setOnScrolled {
                loadMoreRanking()
            }
        }
        fun bind() {}
    }
    
    override fun onCreateViewHolder() {
        DisplayRankingImagesViewHolder(
            loadMoreRanking = loadMoreRanking
        )
    }
}

class DisplayRankingAdapter {...}

// in MainActivity
val adapter = DisplayImagesAdapter(
    loadMoreRanking = {
        viewModel.loadMoreRanking()
    }
)

```

```kotlin=
interface HelloRepository {
    fun hello(): String
}

interface HogeService

class HelloRepositoryImpl(
    private val hogeService: HogeService
) : HelloRepository {...}

class HelloRepositoryTest : HelloRepository {...}

class MainListAdapter(
    private val helloRepository: HelloRepository,
) : ListAdapter(...)

val helloRepository = if (isTest) {
    HelloRepositoryTest()
} else {
    HelloRepositoryImpl(
        hogeService = HogeServiceImple()
    )
}

val adapter = MainListAdapter(
    helloRepository = helloRepository,
)

// koin
single { HelloRepositoryImpl(get()) }
val adapter: MainListAdapter by inject()
```


```kotlin
class RankingAdapter(
    private val update: () -> Unit,
    private val listener: Listener,
) : RecyclerView.Adapter() {
    
    interface Listener {
        fun update()
    }
}

class MainActivity : AppCompatActivity() {
    private val viewModel ....
    
    override fun onCreate(...) {
        
    }
}



val listener = object : RankingAdapter.Listener {
    override fun update() { hello() }
}

val adapter1 = RankingAdapter(
    update = { hello() },
    listener = listener,
)

val adapter2 = RankingAdapter(
    update = { hello() },
    listener = listener,
)

adapter1.update == adapter2.update // false
adapter1.listener == adapter2.listener // true

val update = { hello() }

val adapter3 = RankingAdapter(
    update = update,
    listener = listener,
)
val adapter4 = RankingAdapter(
    update = update,
    listener = listener,
)

adapter3.update == adapter4.update // true
adapter3.listener == adapter4.listener // true
```


```kotlin
val fetchIllustsResult = if (currentKey == null) {} else {}

val illustList = fetchIllustsResult.illusts.map { 
    IllustType.NormalIllust(it) 
}

val loadResultPageData = if (currentKey == null) {
    listOf(
        IllustType.IllustHeader()
    ) + illustList
} else illustList

return LoadResult.Page(

)
```