A transparent way for a decorator pattern (maybe without SimpleTraits)

IMHO using SimpleTraits mostly over engineers traits, they are simple already… Just write them out, it will make it easier to refactor this and simplify the problem.

And try to remove the dispatch on nested types (it’s maybe even a code smell?), instead dispatch on the combinations manually, using A1, B2 etc like traits, instead of creating another trait. That allows you to keep adding combinations in a fairly straightforward way

f(a::A1,x) = x/2 # a lazy default fall back to default
f(a::A2,x) = x-1 # even lazier not using any B
f(a::A3,x) = f(x(a), y(a), a, x)
f(::A1, ::B2, a::A3, x) = 2*x # an explicit non-lazy second case
f(::A2, ::B2, a::A3, x) = x-1

Where x() and y() are getters for A and B objects/types. If I understand what you are trying to do.

3 Likes