# Composition and inheritance: the Julian way

**URL:** https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231
**Category:** General Usage
**Tags:** inheritance, structtypes
**Created:** [May 29, 2018, 1:06pm UTC](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231 "2018-05-29T13:06:00Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 29, 2018, 1:28pm UTC](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231/3 "2018-05-29T13:28:49Z")

</div>

I’ve found the `@forward` macro from Lazy.jl quite useful for this purpose: [https://github.com/MikeInnes/Lazy.jl/blob/76dab7d30863e8375fc96b2444fdb2ead369bf4c/src/macros.jl#L248-L271](https://github.com/MikeInnes/Lazy.jl/blob/76dab7d30863e8375fc96b2444fdb2ead369bf4c/src/macros.jl#L248-L271)

Essentially, you can define:

```julia
struct Person
  name::String
end

name(p::Person) = person.name

struct Citizen
  person::Person 
  nationality::String
end

@forward Citizen.person name

```

which will automatically make `name(c::Citizen) = name(c.person)`

---

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