A reusable collection of methods used to add functionality to a class.
In languages that only support single inheritance, traits provide a safe way to gain flexibility similar to having multiple parent classes (a benefit similar to multiple inheritance). The exact specification differs by language—PHP and Rust each implement it somewhat differently—but it plays a role similar to a mixin.
© 2026 ITBGM