# 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:** 4

<div class="post-metadata">

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

</div>

I don’t think there are rigid rules for every situation. I think of the type system as a set of building blocks, which I can use to design solutions that fit the problem well. I usually try to adhere to the following:

1. abstract types are good for designating interfaces, you can also make a hierarchy of them, keeping [substitutability](https://en.wikipedia.org/wiki/Liskov_substitution_principle) in mind,
2. slots should not be part of the interface, introduce accessor functions, even if trivial,
3. composition is useful and convenient, just forward methods (some macros make this more convenient, eg `Lazy.@forward`).

For a pretty polished and well-maintained example, look at

> **[GitHub - JuliaArrays/OffsetArrays.jl: Fortran-like arrays with arbitrary,...](https://github.com/JuliaArrays/OffsetArrays.jl)**
>
> Fortran-like arrays with arbitrary, zero or negative starting indices. - GitHub - JuliaArrays/OffsetArrays.jl: Fortran-like arrays with arbitrary, zero or negative starting indices.

which is similar to your problem: `OffsetArray`s contain arrays, yet they are also arrays, extending functionality.

---

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