# Closures as "classic object-oriented programming"

**URL:** <https://discourse.julialang.org/t/closures-as-classic-object-oriented-programming/33434>\
**Category:** General Usage\
**Created:** [January 16, 2020, 6:29am UTC](https://discourse.julialang.org/t/closures-as-classic-object-oriented-programming/33434 "2020-01-16T06:29:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [January 16, 2020, 6:29am UTC](https://discourse.julialang.org/t/closures-as-classic-object-oriented-programming/33434/1 "2020-01-16T06:29:20Z")

</div>

This [blog post](https://invenia.github.io/blog/2019/10/30/julialang-features-part-1/#closures-give-us-classic-object-oriented-programming) shows how one could use closures to implement public/private members.

I cannot understand why I can access for instance `get_age` with the dot `newDuck("Bill").get_age()`: I thought the only way to access it was to do the less readable `newDuck("Bill")()[1]()`.

Can anyone explain it to me? Thank you.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 16, 2020, 8:58am UTC](https://discourse.julialang.org/t/closures-as-classic-object-oriented-programming/33434/2 "2020-01-16T08:58:13Z")

</div>

It uses an implementation detail about the representation of closures, namely

[https://docs.julialang.org/en/v1.5-dev/devdocs/functions/#Closures-1](https://docs.julialang.org/en/v1.5-dev/devdocs/functions/#Closures-1)

But I think this is an implementation detail, and not part of the official API, so I would not rely on this.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [January 16, 2020, 10:33am UTC](https://discourse.julialang.org/t/closures-as-classic-object-oriented-programming/33434/3 "2020-01-16T10:33:00Z")

</div>

> [@Tamas\_Papp](#):
>
> an implementation detail about the representation of closures

The blog refers to a [StackOverflow post](https://stackoverflow.com/questions/39133424/how-to-create-a-single-dispatch-object-oriented-class-in-julia-that-behaves-l/39150509#39150509) that is working in Julia v0.5.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 16, 2020, 10:49am UTC](https://discourse.julialang.org/t/closures-as-classic-object-oriented-programming/33434/4 "2020-01-16T10:49:06Z")

</div>

That’s not the question. Sure, it is working, and has been working fine since the beginning, I am just not sure it is part of the API and guaranteed for 1.x.

The devdocs documents internals, which can change.
