# Method inheritance the Julian way

**URL:** <https://discourse.julialang.org/t/method-inheritance-the-julian-way/67198>\
**Category:** New to Julia\
**Tags:** inheritance\
**Created:** [August 28, 2021, 12:58am UTC](https://discourse.julialang.org/t/method-inheritance-the-julian-way/67198 "2021-08-28T00:58:09Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![elenev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elenev/32/18440_2.png) [@elenev](https://discourse.julialang.org/u/elenev)\
**Post date:** [August 28, 2021, 9:05pm UTC](https://discourse.julialang.org/t/method-inheritance-the-julian-way/67198/15 "2021-08-28T21:05:40Z")

</div>

Thanks, all. BTW, I realize the topic has been discussed often but I was missing the right keywords to search for. Now that I know what to look for, these old threads were very relevant and interesting.

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

The solutions are the same – either stick to OOP way of thinking about inheritance and use macros to work around Julia’s “limitations”, or adopt the composition approach suggested by @lmiq and @Sukera with the `Common` struct (perhaps renamed `PetState` or `PetData`) containing all the info that functions dispatching on abstract `Pet` need to be aware of.

There is still the slightly annoying book-keeping issue of accessing fields through nested `getproperty()` calls e.g.

```julia
struct Dog <: Pet
data::PetData
end

d = Dog(PetData("Fido"))
d.name # Error
d.data.name # returns "Fido"

```

But looks like Lazy.@forward can help save time implementing a bunch of pass-through methods like `get_name(pet::Pet) = pet.data.name`. Can probably even overload `getproperty()` but that could come with some performance issues.

---

_[View the full topic](https://discourse.julialang.org/t/method-inheritance-the-julian-way/67198)._
