Well, if we just forward the wrapped field to f
, we are simply inheriting the behavior of A
, not implementing arbitrary new behavior (we would get a MethodError if f(::A, ...)
is not defined).
However, your comment indeed suggests that (f::Function)(b::B, args...) = ...
is probably not the correct implementation of behavior inheritance. It should probably be done differently, not through a “abstract Function method”, but something like @forward
from MacroTools.jl, but that could somehow work for any function. So
@forward B.a
would have the restricted effect of forwarding f(b::B, args...)
to f(b.a, args...)
for any function f