[go: nahoru, domu]

Jump to content

Mixin: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
+zetalisp, LM's Lisp dialect
oops, I forgot that Symbolics was not the only LM maker :P
Line 1: Line 1:
In [[object-oriented programming language]]s, a '''mixin''' is an approach to implementing [[class (computer science)|class]]es that differs from the most widely-used approach coming from the programming language [[Simula]]. Mixins were first used in [[Flavors]], which was an approach to object-orientation used in [[ZetaLisp]] ([[Lisp Machine]] implementation of [[Lisp]]). The advantage of mixins is that they encourage [[code reuse]] and avoid well-known pathologies associated with [[multiple inheritance]], but mixins introduce their own set of compromises.
In [[object-oriented programming language]]s, a '''mixin''' is an approach to implementing [[class (computer science)|class]]es that differs from the most widely-used approach coming from the programming language [[Simula]]. Mixins were first used in [[Flavors]], which was an approach to object-orientation used in [[Lisp Machine Lisp]]. The advantage of mixins is that they encourage [[code reuse]] and avoid well-known pathologies associated with [[multiple inheritance]], but mixins introduce their own set of compromises.


==Definition and implementation==
==Definition and implementation==

Revision as of 13:28, 8 November 2005

In object-oriented programming languages, a mixin is an approach to implementing classes that differs from the most widely-used approach coming from the programming language Simula. Mixins were first used in Flavors, which was an approach to object-orientation used in Lisp Machine Lisp. The advantage of mixins is that they encourage code reuse and avoid well-known pathologies associated with multiple inheritance, but mixins introduce their own set of compromises.

Definition and implementation

In Simula the classes are defined in a block in which attributes, methods and class initialization are all defined together, and so all the methods that can be invoked on a class are defined together, and the definition of the class is complete.

With mixins the class definition defines only the attributes and parameters associated with that class; methods are left to be defined elsewhere, as in Flavours and CLOS, and are called "generic functions". These generic functions are functions which are defined in multiple cases by type dispatch.

Other than Flavors and CLOS, some languages that use mixins are:

Commentary

Some of the functionality of mixins is provided by interfaces in popular languages like Java and C#, but since an interface only specifies what the class must support and cannot provide an implementation, they are only useful for providing polymorphism and not for refactoring common behavior into a single place.