# \#inheritance

**URL:** https://discourse.julialang.org/tag/inheritance/197.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Creating looping matrixes (Torus-like) with type inheritance](https://discourse.julialang.org/t/creating-looping-matrixes-torus-like-with-type-inheritance/135475)

<div class="topic-metadata">

**Author:** [@Daeltam](https://discourse.julialang.org/u/Daeltam)\
**Replies:** 7\
**Last updated:** [February 18, 2026, 11:36pm UTC](https://discourse.julialang.org/t/creating-looping-matrixes-torus-like-with-type-inheritance/135475 "2026-02-18T23:36:13Z")

</div>

Context : I am trying to create a cellular automata and want its behaviour on edges to be looping (ex : neighbour of the cell at \[0,0\] are the cells at \[0,end\] and \[end, 0\] (as well as \[0,1\] and \[1,0\] ) Some kind of tor…

---

## [Composition and inheritance: the Julian way](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231)

<div class="topic-metadata">

**Author:** [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Replies:** 133\
**Last updated:** [May 14, 2024, 5:41pm UTC](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231 "2024-05-14T17:41:01Z")

</div>

I am a relatively newbie and I am wondering what is the most appropriate Julian way to reuse the code. I don’t want to trigger discussions on topics already discussed a million times. This post simply aims to lay down …

---

## [Required function input types in PyJulia](https://discourse.julialang.org/t/required-function-input-types-in-pyjulia/100580)

<div class="topic-metadata">

**Author:** [@lkmc](https://discourse.julialang.org/u/lkmc)\
**Replies:** 0\
**Last updated:** [June 19, 2023, 11:18pm UTC](https://discourse.julialang.org/t/required-function-input-types-in-pyjulia/100580 "2023-06-19T23:18:26Z")

</div>

I have a function in Julia that is called from Python and it seems to be enforcing a particular argument type, but I’m not sure how/where because when I change the allowed argument type to what should be the correct thin…

---

## [Is it ok to write interfaces that require field access on subtypes?](https://discourse.julialang.org/t/is-it-ok-to-write-interfaces-that-require-field-access-on-subtypes/98429)

<div class="topic-metadata">

**Author:** [@aleferna12](https://discourse.julialang.org/u/aleferna12)\
**Replies:** 6\
**Last updated:** [May 8, 2023, 9:12am UTC](https://discourse.julialang.org/t/is-it-ok-to-write-interfaces-that-require-field-access-on-subtypes/98429 "2023-05-08T09:12:04Z")

</div>

Hello! Since we can’t define fields on abstract types (at least yet, see this very long discussion), I was wondering whether the following design pattern is considered good practice in Julia: abstract type A end struc…

---

## [Generate a (mutable) struct which inherits others](https://discourse.julialang.org/t/generate-a-mutable-struct-which-inherits-others/47347)

<div class="topic-metadata">

**Author:** [@iHany](https://discourse.julialang.org/u/iHany)\
**Replies:** 12\
**Last updated:** [April 3, 2023, 10:48pm UTC](https://discourse.julialang.org/t/generate-a-mutable-struct-which-inherits-others/47347 "2023-04-03T22:48:50Z")

</div>

Hi. Is there any way for a (mutable) struct to inherit fields from others? For example, what I’m trying to do is: mutable struct Parent foo bar end mutable struct Child \<: Parent end and use child = Child();…

---

## [RFC: Language Support for Traits — Yay or Nay?](https://discourse.julialang.org/t/rfc-language-support-for-traits-yay-or-nay/93914)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 45\
**Last updated:** [February 8, 2023, 1:51am UTC](https://discourse.julialang.org/t/rfc-language-support-for-traits-yay-or-nay/93914 "2023-02-08T01:51:46Z")

</div>

A repeated gripe I see from the local gray-hairs about Julia’s type system pertains to the lack of language support for multiple inheritance through traits—to manage those pesky behaviors that fall outside the type hiera…

---

## [Metaprogramming: Obtain actual type from Symbol for field inheritance](https://discourse.julialang.org/t/metaprogramming-obtain-actual-type-from-symbol-for-field-inheritance/84912)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 15\
**Last updated:** [July 29, 2022, 8:55am UTC](https://discourse.julialang.org/t/metaprogramming-obtain-actual-type-from-symbol-for-field-inheritance/84912 "2022-07-29T08:55:22Z")

</div>

Hello, I admit, having read How to get the type of a symbol in a macro? I realize that this may be harder than I thought, but perhaps if I describe what I want to achieve, a solution can be made for this specific case. …

---

## [\[ANN\] ObjectOriented.jl (renamed from TyOOP.jl), complete OOP support](https://discourse.julialang.org/t/ann-objectoriented-jl-renamed-from-tyoop-jl-complete-oop-support/83911)

<div class="topic-metadata">

**Author:** [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Replies:** 31\
**Last updated:** [July 15, 2022, 5:00pm UTC](https://discourse.julialang.org/t/ann-objectoriented-jl-renamed-from-tyoop-jl-complete-oop-support/83911 "2022-07-15T17:00:18Z")

</div>

Hi community! It has been quite a long time since my last post, and now I’m glad to say that I have completed my postgraduate career and started working with Julia! :sunglasses: I made this package (EDIT) initially for…

---

## [Dispatch on type aliases?](https://discourse.julialang.org/t/dispatch-on-type-aliases/70691)

<div class="topic-metadata">

**Author:** [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Replies:** 7\
**Last updated:** [October 31, 2021, 5:23pm UTC](https://discourse.julialang.org/t/dispatch-on-type-aliases/70691 "2021-10-31T17:23:12Z")

</div>

Can Julia have dispatch based on type aliases? Something rather similar to Scala 3’s opaque type aliases. const MyTypeAlias = Float64 a::MyTypeAlias = 78.0 # The compiler should implicitly convert this from Float64 to M…

---

## [How to simplify the code in constructing struct](https://discourse.julialang.org/t/how-to-simplify-the-code-in-constructing-struct/70411)

<div class="topic-metadata">

**Author:** [@zhangjin](https://discourse.julialang.org/u/zhangjin)\
**Replies:** 5\
**Last updated:** [October 31, 2021, 3:46am UTC](https://discourse.julialang.org/t/how-to-simplify-the-code-in-constructing-struct/70411 "2021-10-31T03:46:09Z")

</div>

I know the julia don’t have the “class”, but I need it. So I try to use struct to complete it. I try to implement the initialization of inheritance like following code. struct P1 M::Int8 Ks::Int8 metric::St…

---

## [Method inheritance the Julian way](https://discourse.julialang.org/t/method-inheritance-the-julian-way/67198)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 18\
**Last updated:** [August 29, 2021, 11:18am UTC](https://discourse.julialang.org/t/method-inheritance-the-julian-way/67198 "2021-08-29T11:18:09Z")

</div>

Suppose I am trying to describe the behavior of a Pet. I implemented several methods common to all instances of Pet e.g. eat(pet::Pet) and walk(pet::Pet, towards). I also want to define function greet(pet::Pet, person::…

---

## [Deep dive detangling terms: multiple inheritance vs. traits](https://discourse.julialang.org/t/deep-dive-detangling-terms-multiple-inheritance-vs-traits/67110)

<div class="topic-metadata">

**Author:** [@bgroenks](https://discourse.julialang.org/u/bgroenks)\
**Replies:** 10\
**Last updated:** [August 24, 2021, 1:11pm UTC](https://discourse.julialang.org/t/deep-dive-detangling-terms-multiple-inheritance-vs-traits/67110 "2021-08-24T13:11:48Z")

</div>

I did not read issue 5, I am just expressing my view on this subject. I don’t agree with this use of the phrase “multiple inheritance”. In PL theory, traits and inheritance are separate concepts, though they can be use…

---

## [Multiple Parent Types: How to go about it?](https://discourse.julialang.org/t/multiple-parent-types-how-to-go-about-it/66493)

<div class="topic-metadata">

**Author:** [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Replies:** 22\
**Last updated:** [August 24, 2021, 9:29am UTC](https://discourse.julialang.org/t/multiple-parent-types-how-to-go-about-it/66493 "2021-08-24T09:29:55Z")

</div>

There are many cases where we would like to assign multiple parents to a given type, e.g: abstract type Person end abstract type Soldier \<: Person end abstract type Civilian \<: Person end abstract type Man \<: Person e…

---

## [Function reusing in Julia without inheritance](https://discourse.julialang.org/t/function-reusing-in-julia-without-inheritance/66108)

<div class="topic-metadata">

**Author:** [@hideakiv](https://discourse.julialang.org/u/hideakiv)\
**Replies:** 3\
**Last updated:** [August 10, 2021, 7:14am UTC](https://discourse.julialang.org/t/function-reusing-in-julia-without-inheritance/66108 "2021-08-10T07:14:49Z")

</div>

Suppose I have struct Var x::Float64 end and function square(x::Float64) return x^2 end To define a function for squaring a Var and returning a Var, I could write function square(var::Var) y = square(var…

---

## [Why use subtypes instead of traits and duck typing?](https://discourse.julialang.org/t/why-use-subtypes-instead-of-traits-and-duck-typing/59146)

<div class="topic-metadata">

**Author:** [@regier2302](https://discourse.julialang.org/u/regier2302)\
**Replies:** 32\
**Last updated:** [April 15, 2021, 3:58pm UTC](https://discourse.julialang.org/t/why-use-subtypes-instead-of-traits-and-duck-typing/59146 "2021-04-15T15:58:50Z")

</div>

I have been tinkering with Julia and I am now trying to design a moderate-sized project. However, I have been struggling to come up with a type hierarchy and I realized that, in Julia, I don’t know why you should subtype…

---

## [Inheriting from a Type Parameter](https://discourse.julialang.org/t/inheriting-from-a-type-parameter/59010)

<div class="topic-metadata">

**Author:** [@gphlipot](https://discourse.julialang.org/u/gphlipot)\
**Replies:** 1\
**Last updated:** [April 10, 2021, 9:38pm UTC](https://discourse.julialang.org/t/inheriting-from-a-type-parameter/59010 "2021-04-10T21:38:41Z")

</div>

I’m curious why Julia doesn’t let you define a parametric type that inherits from a parameter, e.g. struct SomeType{T} \<: T end When I try this, Julia gives the error invalid subtyping in definition of SomeType. It se…

---

## [Supertype method call inside subtype method with same name](https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 2\
**Last updated:** [April 7, 2021, 8:33am UTC](https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720 "2021-04-07T08:33:39Z")

</div>

I defined some struct that is the subtype of Parent. There is a method I’d like to change for the Child type but at the same time I want it to call the same method for Parent type. What is the correct way to get this …

---

## [Multiple inheritance carry-over members](https://discourse.julialang.org/t/multiple-inheritance-carry-over-members/58355)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 13\
**Last updated:** [April 6, 2021, 7:21am UTC](https://discourse.julialang.org/t/multiple-inheritance-carry-over-members/58355 "2021-04-06T07:21:31Z")

</div>

Inheritance vs. mulitple dispatch in julia is maybe one of the hard things to grasp. I am still struggling with it and therefore the question. Does julia have a concept of carrying over data members to derived classes? I…

---

## [Invoke different method for callable struct / How to emulate pythons \`super()\`](https://discourse.julialang.org/t/invoke-different-method-for-callable-struct-how-to-emulate-pythons-super/57869)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 4\
**Last updated:** [March 24, 2021, 5:01pm UTC](https://discourse.julialang.org/t/invoke-different-method-for-callable-struct-how-to-emulate-pythons-super/57869 "2021-03-24T17:01:46Z")

</div>

I have a parametric function as discussed here and now want to generate another such function type that logs its arguments while invoking the non-logging method for the computation. How do I use invoke to dispatch on the…

---

## [Union Type vs Inheritance from Abstract Type](https://discourse.julialang.org/t/union-type-vs-inheritance-from-abstract-type/53000)

<div class="topic-metadata">

**Author:** [@ykkan](https://discourse.julialang.org/u/ykkan)\
**Replies:** 9\
**Last updated:** [January 8, 2021, 6:26am UTC](https://discourse.julialang.org/t/union-type-vs-inheritance-from-abstract-type/53000 "2021-01-08T06:26:41Z")

</div>

If I have several structures: struct Child1{N,T} end struct Child2{T} end const Child1OrChild2{N,T} = Union{Child1{N,T}, Child2{T}} struct Mother{M,N,T} children::NTuple{M,Child1OrChild2{N,T}} end Would it be possi…

---

## [ExtensibleUnions.jl - experiments in abstract multiple inheritance via extensible type unions](https://discourse.julialang.org/t/extensibleunions-jl-experiments-in-abstract-multiple-inheritance-via-extensible-type-unions/27920)

<div class="topic-metadata">

**Author:** [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Replies:** 2\
**Last updated:** [December 21, 2020, 11:44am UTC](https://discourse.julialang.org/t/extensibleunions-jl-experiments-in-abstract-multiple-inheritance-via-extensible-type-unions/27920 "2020-12-21T11:44:46Z")

</div>

Hi all - I wanted to share a small experimental package that I have started working on called ExtensibleUnions.jl. As discussed in these comments, “extensible type unions are largely equivalent to multiple inheritance”.…

---

## [About inheritance and abstract types](https://discourse.julialang.org/t/about-inheritance-and-abstract-types/5801)

<div class="topic-metadata">

**Author:** [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Replies:** 46\
**Last updated:** [June 12, 2020, 8:47pm UTC](https://discourse.julialang.org/t/about-inheritance-and-abstract-types/5801 "2020-06-12T20:47:23Z")

</div>

There’s something about Julia style that I’m just not getting. Let’s say I want a Curve type for a curve in the complex plane. It’s meant to be abstract, since I will have different subtypes of Curve (Line, Circle, etc).…

---

## [Property Inheritance Pattern](https://discourse.julialang.org/t/property-inheritance-pattern/40101)

<div class="topic-metadata">

**Author:** [@virtualgraham](https://discourse.julialang.org/u/virtualgraham)\
**Replies:** 20\
**Last updated:** [May 26, 2020, 3:09am UTC](https://discourse.julialang.org/t/property-inheritance-pattern/40101 "2020-05-26T03:09:36Z")

</div>

As of version 1.4 Julia does not support property inheritance. However, many other languages such as Python do support inheritance and porting libraries from these languages becomes difficult. I am proposing an informal…

---

## [Generating a type inheritance diagram](https://discourse.julialang.org/t/generating-a-type-inheritance-diagram/32773)

<div class="topic-metadata">

**Author:** [@yuxi.liu](https://discourse.julialang.org/u/yuxi.liu)\
**Replies:** 3\
**Last updated:** [December 29, 2019, 4:57am UTC](https://discourse.julialang.org/t/generating-a-type-inheritance-diagram/32773 "2019-12-29T04:57:30Z")

</div>

I want to see a type inheritance diagram of Julia’s classes, such as Base. Is there a tool to view it?

---

## [How to access shared "inherited" fields without paying multiple dispatch performance price?](https://discourse.julialang.org/t/how-to-access-shared-inherited-fields-without-paying-multiple-dispatch-performance-price/26762)

<div class="topic-metadata">

**Author:** [@Russ](https://discourse.julialang.org/u/Russ)\
**Replies:** 14\
**Last updated:** [July 25, 2019, 9:46am UTC](https://discourse.julialang.org/t/how-to-access-shared-inherited-fields-without-paying-multiple-dispatch-performance-price/26762 "2019-07-25T09:46:23Z")

</div>

Hi, I’m evaluating Julia to replace some old C++ code. The code uses inheritance where there is a single base class and lots (100’s) of derived classes. There are a large number of instances, and the code needs to be abl…

---

## [How to enforce the fields to be inherited?](https://discourse.julialang.org/t/how-to-enforce-the-fields-to-be-inherited/20693)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 8\
**Last updated:** [February 12, 2019, 10:45am UTC](https://discourse.julialang.org/t/how-to-enforce-the-fields-to-be-inherited/20693 "2019-02-12T10:45:36Z")

</div>

hello, coming across StatsBase.AbstractWeights, I found it could enforce fields to be inherited. e.g. import StatsBase struct MyWeights1{S\<:Real, T\<:Real, V\<:AbstractVector{T}} \<: StatsBase.AbstractWeights{S, T, V} …

---

## [Why doesn't Julia allow multiple inheritance?](https://discourse.julialang.org/t/why-doesnt-julia-allow-multiple-inheritance/14342)

<div class="topic-metadata">

**Author:** [@lcmylin](https://discourse.julialang.org/u/lcmylin)\
**Replies:** 8\
**Last updated:** [August 31, 2018, 12:29pm UTC](https://discourse.julialang.org/t/why-doesnt-julia-allow-multiple-inheritance/14342 "2018-08-31T12:29:16Z")

</div>

To be clear, when I write “multiple inheritance” in this context, I don’t mean multiple structural inheritance (as in C++), but rather multiple abstract class inheritance. In other words, the allowance for a node in the …

---

## [Merging composite types - multiple inheritance of fields/mixins](https://discourse.julialang.org/t/merging-composite-types-multiple-inheritance-of-fields-mixins/10458)

<div class="topic-metadata">

**Author:** [@Raf](https://discourse.julialang.org/u/Raf)\
**Replies:** 3\
**Last updated:** [April 21, 2018, 11:23pm UTC](https://discourse.julialang.org/t/merging-composite-types-multiple-inheritance-of-fields-mixins/10458 "2018-04-21T23:23:28Z")

</div>

This has been talked about a lot before - the lack of mixin functionality in julia. But I’ve been thinking about mixins a lot – for merging existing composite types to balance modularity with simplicity when using lots…

---

## [Numeric types and their relationships](https://discourse.julialang.org/t/numeric-types-and-their-relationships/7869)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 14\
**Last updated:** [December 21, 2017, 1:20am UTC](https://discourse.julialang.org/t/numeric-types-and-their-relationships/7869 "2017-12-21T01:20:58Z")

</div>

Suppose I need to define a parametric type with numeric values that are real numbers, but not integers. Initially I thought of doing something like: struct Foo{Integer\<:T\<:Real} end but I am aware that it has two issu…

---

## [Workaround for traditional inheritance features in object-oriented languages](https://discourse.julialang.org/t/workaround-for-traditional-inheritance-features-in-object-oriented-languages/1195)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 40\
**Last updated:** [November 14, 2017, 3:03am UTC](https://discourse.julialang.org/t/workaround-for-traditional-inheritance-features-in-object-oriented-languages/1195 "2017-11-14T03:03:04Z")

</div>

I am using the Julia type system seriously for the first time and have just learned that it doesn’t support inheritance from non-abstract types nor multiple inheritance. This statement applies to Julia v0.5. Could you p…

[Next page](https://discourse.julialang.org/tag/inheritance/197.md?match_all_tags=true&page=1&tags%5B%5D=inheritance)
