# Property Inheritance Pattern

**URL:** <https://discourse.julialang.org/t/property-inheritance-pattern/40101>\
**Category:** General Usage\
**Tags:** inheritance, structtypes\
**Created:** [May 25, 2020, 2:34am UTC](https://discourse.julialang.org/t/property-inheritance-pattern/40101 "2020-05-25T02:34:12Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![virtualgraham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/virtualgraham/32/15200_2.png) [@virtualgraham](https://discourse.julialang.org/u/virtualgraham)\
**Post date:** [May 26, 2020, 3:09am UTC](https://discourse.julialang.org/t/property-inheritance-pattern/40101/21 "2020-05-26T03:09:36Z")

</div>

Ok so here is the final working version that has been tested fairly well:

```julia
abstract type Object end

function Base.getproperty(o::Object, s::Symbol)
    if hasfield(typeof(o), s) 
        return getfield(o, s)
    end
    return getproperty(getfield(o, :super), s)
end

function Base.setproperty!(o::Object, s::Symbol, x)
    t = typeof(o)
    if hasfield(t, s) 
        setfield!(o, s, convert(fieldtype(t, s), x))
    else
        setproperty!(getfield(o, :super), s, x)
    end
end

```

[Previous page](https://discourse.julialang.org/t/property-inheritance-pattern/40101.md?page=1)
