# Is multiple inheritance allowed (or to be allowed) in Julia?

**URL:** <https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096>\
**Category:** General Usage\
**Tags:** proposal, inheritance\
**Created:** [June 5, 2017, 9:44pm UTC](https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096 "2017-06-05T21:44:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 5, 2017, 9:44pm UTC](https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096/1 "2017-06-05T21:44:46Z")

</div>

I am faced with an application which could use multiple inheritance to avoid repetition and arbitrariness in the type tree structure. As you know, multiple inheritance is nice to have when there 2 or more independent ways to classify the types, each associated with some behaviour. So I wonder if such a thing exists in Julia or if it may be added in the future.

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [June 5, 2017, 10:18pm UTC](https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096/2 "2017-06-05T22:18:21Z")

</div>

Multiple inheritance is pretty unlikely to make it into Julia, but [traits](https://github.com/mauro3/SimpleTraits.jl) already work, and may eventually be integrated into the language.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 5, 2017, 10:46pm UTC](https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096/3 "2017-06-05T22:46:12Z")

</div>

Interesting. From a quick scan, I realize traits can be used to define constraints on types while dispatching, that is defining traits that the arguments’ types should respect. I will read more on sub-traits; they could provide an alternative to multiple inheritance. Thanks.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [June 6, 2017, 2:45am UTC](https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096/4 "2017-06-06T02:45:54Z")

</div>

I’d also recommend traits, as @cstjean did. Another thing is to use composition instead of (multiple) inheritance.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 6, 2017, 3:03am UTC](https://discourse.julialang.org/t/is-multiple-inheritance-allowed-or-to-be-allowed-in-julia/4096/5 "2017-06-06T03:03:31Z")

</div>

I describe how to use traits and small functions to allow for multiple inheritance in here:

> **[Type-Dispatch Design: Post Object-Oriented Programming for Julia - Stochastic...](http://www.stochasticlifestyle.com/type-dispatch-design-post-object-oriented-programming-julia/)**
>
> In this post I am going to try to explain in detail the type-dispatch design which is used in Julian software architectures. It's modeled after the design of many different packages and Julia Base, and has been discussed in parts elsewhere. This is...

I think that programming Julia requires a bit more of a change from standard OO thinking though, and that you should always be thinking about inheriting behavior/actions and not implementation.
