# Cal function from another class/interface

**URL:** <https://discuss.kotlinlang.org/t/cal-function-from-another-class-interface/19910>\
**Category:** Support\
**Created:** [November 14, 2020, 12:15pm UTC](https://discuss.kotlinlang.org/t/cal-function-from-another-class-interface/19910 "2020-11-14T12:15:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitriy](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@Dmitriy](https://discuss.kotlinlang.org/u/Dmitriy)\
**Post date:** [November 14, 2020, 12:15pm UTC](https://discuss.kotlinlang.org/t/cal-function-from-another-class-interface/19910/1 "2020-11-14T12:15:40Z")

</div>

Hello guys)  
I using ROOM request-function inside my ViewModel class(like a “ClearData”). Help me please transfer my function “ClearData” to another class/interface and just call it from ViewModel class.

```
class TitleViewModel( val databasedao: CountDataBaseDao, application: Application): AndroidViewModel(application) {

//here different code

   //This function i need to call from another place, i should manage this function at another place and here just call it

    fun clearData(){
        viewModelScope.launch {
        databasedao.clear()
        }
        _count.value=0
    }

}

```

what i want - something like that :

```
class TitleViewModel( val databasedao: CountDataBaseDao, application: Application): AndroidViewModel(application), WorkWithDataBase {

fun clear(){
               clearDataWork()} //but i cant just call this function - interface want make me override this fun
}

```

My interface which contains function clearDataWork()

```
 interface WorkWithDataBase {

 fun clearDataWork(count: MutableLiveData<Int>,dataSource: CountDataBaseDao){
        GlobalScope.launch {
            dataSource.clear()
        }
        count.value=0
    }
}

```

Totally i want recode my project [GitHub - bboykot/myRepo](https://github.com/bboykot/myRepo) to more SOLID (transfer dataBase functions to one place and call it in my ViewModels classes).  
Help please.

---

<div class="post-metadata">

**Author:** ![Dmitriy](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@Dmitriy](https://discuss.kotlinlang.org/u/Dmitriy)\
**Post date:** [November 15, 2020, 2:35pm UTC](https://discuss.kotlinlang.org/t/cal-function-from-another-class-interface/19910/2 "2020-11-15T14:35:39Z")

</div>

Problem solved.
