# Implementation delegation of inherited interfaces

**URL:** <https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958>\
**Category:** Language Design\
**Created:** [October 22, 2018, 1:59pm UTC](https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958 "2018-10-22T13:59:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![programmerr47](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@programmerr47](https://discuss.kotlinlang.org/u/programmerr47)\
**Post date:** [October 22, 2018, 1:59pm UTC](https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958/1 "2018-10-22T13:59:11Z")

</div>

Suppose we have next `interface`:

```auto
interface TabsInfo : Iterable<Tab>

```

Then we can not write:

```auto
class TabsBuilder(
    private val tabs: Iterable<Tab> = mutableListOf()
) : TabsInfo by tabs {
    //...other code
}

```

I understand why. Because `TabsInfo` can extend `Iterable` by introducing new methods.  
But apparently we can write:

```auto
class TabsBuilder(
    private val tabs: Iterable<Tab> = mutableListOf()
): TabsInfo, Iterable<Tab> by tabs {
   //...other code
}

```

So in general it is possible to provide delegation pattern for inherited interfaces.  
The question is: is it planned or maybe is there a wish to plan supporting of delegation `by` for inherited interfaces, so first example will be acceptable. For example, if `TabsInfo` had additional method, then we need to implement it in `TabsBuilder` according to first and second examples, but we will not need to specify additional interface in `TabsBuilder` class declaration like in second example.Preformatted text

---

<div class="post-metadata">

**Author:** ![ilogico](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilogico/32/3725_2.png) [@ilogico](https://discuss.kotlinlang.org/u/ilogico)\
**Post date:** [October 23, 2018, 7:47am UTC](https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958/2 "2018-10-23T07:47:59Z")

</div>

The first case doesn’t compile because you cannot delegate the implementation to something that doesn’t implement the interface.  
But defining the type like: `typealias TabInfo = Iterable<Tab>` would’ve worked.

---

<div class="post-metadata">

**Author:** ![programmerr47](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@programmerr47](https://discuss.kotlinlang.org/u/programmerr47)\
**Post date:** [November 9, 2018, 9:35am UTC](https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958/3 "2018-11-09T09:35:34Z")

</div>

`TabsInfo` implements required interface. And, also, I can not convert `TabsInfo` interface to typealias, since it has additional methods.

The point is, that I can provide a delegation, but for that I need to explicitly say, that `TabsBuilder` implements `Iterable<Tab>`, although it already implements this interface, since it implements `TabsInfo`, which implements `Iterable<Tab>`

---

<div class="post-metadata">

**Author:** ![ilogico](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilogico/32/3725_2.png) [@ilogico](https://discuss.kotlinlang.org/u/ilogico)\
**Post date:** [November 15, 2018, 9:07pm UTC](https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958/4 "2018-11-15T21:07:00Z")

</div>

TabsInfo doesn’t implement anything. It’s an interface, not an implementation.  
I meant MutableInterface does not implement TabsInfo because there is no structural typing in Kotlin, Classes have to declare the interfaces they implement.

---

<div class="post-metadata">

**Author:** ![programmerr47](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@programmerr47](https://discuss.kotlinlang.org/u/programmerr47)\
**Post date:** [November 27, 2018, 7:11am UTC](https://discuss.kotlinlang.org/t/implementation-delegation-of-inherited-interfaces/9958/5 "2018-11-27T07:11:43Z")

</div>

Okey, thank you for your remark. I will fix my phrase:

" `TabsInfo` extends required interface (Iterable). And, also, I can not convert `TabsInfo` interface to typealias, since it has declared additional methods.

The point is, that I can provide a delegation, but for that I need to explicitly say, that `TabsBuilder` implements `Iterable<Tab>` , although it already implements this interface, since it implements `TabsInfo` , which implements `Iterable<Tab>`"

Once again, point is that implementing `TabsInfo`, `TabsBuilder` will have to implement `Iterable` methods, and become Iterable. But `TabsBuilder` have a `Iterable` property passed through the constructor and, suppose, want to delegate such functionality to it. To do that, I need to explicitly write that `TabsBuilder` implements `Iterable`, but it is obvious, since `TabsBuilder` implements `TabsInfo`. Please, read once again my first example, ignoring my mistake in terms “extends” and “implements”. 🙂
