# Composition visibility

**URL:** <https://discuss.kotlinlang.org/t/composition-visibility/26465>\
**Category:** Language Design\
**Created:** [March 3, 2023, 6:17pm UTC](https://discuss.kotlinlang.org/t/composition-visibility/26465 "2023-03-03T18:17:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Psijic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/psijic/32/2227_2.png) [@Psijic](https://discuss.kotlinlang.org/u/Psijic)\
**Post date:** [March 3, 2023, 6:17pm UTC](https://discuss.kotlinlang.org/t/composition-visibility/26465/1 "2023-03-03T18:17:07Z")

</div>

I suppose, internal visibility is rarely used in projects because it’s wide and packages are shuffled often. But what could be useful is a visibility scope to be seen only between children and parents or composition variables. Like

```auto
class Foo() {
    internal_private fun invisibleOutside() {}
}

class Bar(foo: Foo) {
    init {
        foo.invisibleOutside()
    }
}

```

And it’s good to be available in interfaces as well.

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [March 3, 2023, 9:34pm UTC](https://discuss.kotlinlang.org/t/composition-visibility/26465/2 "2023-03-03T21:34:51Z")

</div>

What do you mean by “children and parents or composition variables”? When exactly should it be visible?

Visibility modifiers is a looong story in Kotlin 🙂 BTW, I personally use `internal` quite a lot.

---

<div class="post-metadata">

**Author:** ![arocnies](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/arocnies/32/5143_2.png) [@arocnies](https://discuss.kotlinlang.org/u/arocnies)\
**Post date:** [March 3, 2023, 10:21pm UTC](https://discuss.kotlinlang.org/t/composition-visibility/26465/3 "2023-03-03T22:21:21Z")

</div>

If you’re using modules then `internal` should be pretty common.  
The Gradle docs do a decent job of pointing in the right direction for structuring projects: [Structuring Large Projects](https://docs.gradle.org/current/userguide/structuring_software_products.html#structure_large_projects)  
^ The next few pages on that link talk about best practices, etc.

---

<div class="post-metadata">

**Author:** ![Psijic](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/psijic/32/2227_2.png) [@Psijic](https://discuss.kotlinlang.org/u/Psijic)\
**Post date:** [March 4, 2023, 10:01am UTC](https://discuss.kotlinlang.org/t/composition-visibility/26465/4 "2023-03-04T10:01:37Z")

</div>

As I remember, custom visibility scope can be created, but I don’t remember if Java supports it.  
Something like only close family can use it, between internal and protected. Maybe the visibility inside of a single package could be enough.
