Inherit.jl provides macros for inheriting fields and interface declarations from a supertype. The macros generate native Julia types so you can work with familiar syntax while ensuring that required methods are implemented.
using Inherit
@abstractbase struct Fruit
weight::Float64
function cost(fruit::Fruit, unitprice::Float64) end
end
@implement struct Apple <: Fruit
coresize::Int
end
function cost(apple::Apple, unitprice::Float64)
apple.weight * unitprice * (apple.coresize < 5 ? 2.0 : 1.0)
end
println(cost(Apple(3.0, 4), 1.0))
# output
6.0
Further resources: