Chapter 5
How does delegation pattern work?
Delegation pattern can be implemented by wrapping a parent object in a new object. The function for the new objects can be forwarded (or delegated) to the parent object.
What is the purpose of traits?
The purpose of traits is to formally define the behavior of certain objects. Once a trait is defined, we can programmatically examine whether an object exhibits the trait.
Are traits always binary?
Traits are typically binary, but there is no mandatory requirement. It would be fine as long as the traits are mutually exclusive. Julia's Base.IteratorSize trait is a good example of a multi-valued trait.
Can traits be used for objects from a different type hierarchy?
Yes, traits are not restricted by ...
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