Skip to content

Latest commit

 

History

History
11 lines (6 loc) · 662 Bytes

traits.md

File metadata and controls

11 lines (6 loc) · 662 Bytes

Traits

Traits also gives another alternative for Multiple Inheritance.

Traits are used to declare methods that can be used in multiple classes. Traits can have methods and abstract methods that can be used in multiple classes.

A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an additional to traditional inheritance and enables horizontal composition of behavior, that is, the application of class members without requiring inheritance.

Traits vs Mixins

The main difference is that Mixins can have state while traits don't.