The holy traits pattern
The holy traits pattern has an interesting name. Some people also call it the Tim Holy Traits Trick (THTT). As you might have guessed the pattern is named after Tim Holy, who is a long-time contributor to the Julia language and ecosystem.
What are traits? In a nutshell, a trait corresponds to the behavior of an object. For example, birds and butterflies can fly, so they both have the CanFly trait. Dolphins and turtles can swim, so they both have the CanSwim trait. A duck can fly and swim, so it has both the CanFly and CanSwim traits. Traits are typically binary – you either exhibit the trait or not – although that is not a mandatory requirement.
Why do we want traits? Traits can be used as a formal contract about how ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access