= Mixins = == Introduction == To be done. In the mean time, see the [http://cobra-language.com/forums/viewtopic.php?f=4&t=306 discussion thread]. == Compared to Extensions == * Extensions enable adding methods to existing classes whereas mixins only augment types that you declare. * Mixins can add state (object variables declared with `var`) whereas extensions cannot. * Mixins can add properties whereas extensions cannot. * Mixin members will be found at run-time via reflection whereas extension members will not. * Mixins create new types. From a VirtualMachine perspective, they are seen as interfaces (since the popular VMs don't support mixins). * Mixins cannot be used from a [wiki:BinaryLibrary binary library]. The source must be included for the compiler. 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). == Restrictions == 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: * Mixins cannot declare initializers. * Mixins cannot inherit from other types. * Mixins cannot implement interfaces. * Mixins cannot add other mixins. * Mixins cannot declare generic parameters (see [http://cobra-language.com/forums/viewtopic.php?f=4&t=532 forum's thread]) nor being generic themselves (see [http://cobra-language.com/forums/viewtopic.php?f=4&t=533 forum's thread]). * Mixins cannot add invariants. * Two or more mixins added to a single type cannot have collision in their member names. == See also == * [http://cobra-language.com/trac/cobra/browser/cobra/trunk/Tests/150-mixins/ Test cases] in the Subversion repository * [http://cobra-language.com/forums/viewtopic.php?f=4&t=306 Announcement thread] on discussion forums * [http://cobra-language.com/forums/search.php?keywords=mixin "mixin" search] on discussion forums * [http://bloggingabout.net/blogs/erwyn/archive/2005/10/20/9925.aspx A blog post] by Erwyn Van Der Meer covers limitations experienced without mixins, and the various suboptimal workarounds.