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

**URL:** <https://discourse.julialang.org/t/a-transparent-way-for-a-decorator-pattern-maybe-without-simpletraits/31446>\
**Category:** General Usage\
**Created:** [November 24, 2019, 8:44am UTC](https://discourse.julialang.org/t/a-transparent-way-for-a-decorator-pattern-maybe-without-simpletraits/31446 "2019-11-24T08:44:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [November 24, 2019, 1:04pm UTC](https://discourse.julialang.org/t/a-transparent-way-for-a-decorator-pattern-maybe-without-simpletraits/31446/2 "2019-11-24T13:04:53Z")

</div>

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

```julia
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.

---

_[View the full topic](https://discourse.julialang.org/t/a-transparent-way-for-a-decorator-pattern-maybe-without-simpletraits/31446)._
