1 | | (coming soon) |
| 1 | = Mixins = |
| 2 | |
| 3 | == Compared to Extensions == |
| 4 | |
| 5 | * Extensions enable adding methods to existing classes whereas mixins only augment types that you declare. |
| 6 | * Mixins can add state (object variables declared with `var`) whereas extensions cannot. |
| 7 | * Mixins can add properties whereas extensions cannot. |
| 8 | * Mixin members will be found at run-time via reflection whereas extension members will not. |
| 9 | |
| 10 | In summary, mixins are more about multiple inheritance among the types you are declaring. Extensions are about adding convenience methods to existing types (regardless of who declared them). |
| 11 | |
| 12 | == Restrictions == |
| 13 | |
| 14 | As we gain more experience with using mixins, and as the implementation of mixins matures, some of the following restrictions are likely to be removed: |
| 15 | |
| 16 | * Mixins cannot inherit from other types. |
| 17 | * Mixins cannot implement interfaces. |
| 18 | * Mixins cannod add other mixins. |
| 19 | * Mixins cannot declare generic parameters. |
| 20 | * Mixins cannot add invariants. |
| 21 | * Two or more mixins added to a single type cannot have collision in their member names. |
| 22 | |
| 23 | == See also == |
| 24 | |
| 25 | * [http://cobra-language.com/trac/cobra/browser/cobra/trunk/Tests/150-mixins/ Test cases] in the Subversion repository |
| 26 | * [http://cobra-language.com/forums/viewtopic.php?f=4&t=306 Announcement thread] on discussion forms |