Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Since I don't see this term elsewhere in a PerlMonks search and it doesn't appear in the index of any of my dozen perl books, could someone provide a clear explanation and description of 'mixins'? What they are, what they're intended to solve and so on?

Basically a mixin is a partial-class that makes no sense by itself, but can be "mixed in" to another class to supply additional functionality.

The classic example is adding borders to different kinds of windows in a GUI framework. You have your normal GUI widgets and have a border mixin that you use to create widget classes that draw their borders. You add the border drawing behaviour to the classes with the mixin.

So rather than specialising behaviour in a subclass you add additional behaviour with a mixin.

DIfferent OO languages support mixins in different ways. Some like Perl and C++ have no explicit support and you implement them with other features like multiple inheritance or symbol table fiddling. Other languages like Ruby and Flavors have explicit support for mixin classes.

The "mixin" terms comes from the Flavors langauge - one of the earliest object oriented languages that ran on Lisp Machines. The name came from the (in)famous ice cream metaphor used by the language (the base class was called 'Vanilla') due to an popular ice cream store used by MIT students - Steve's Ice Cream.

At Steve's you ordered a code or dish and specified the base flavour and any mixin flavours. You then got a scoop of the base with spoonfuls of mixin flavours on top.

In reply to Re^2: Implementing a Mixin Class (please explain?) by adrianh
in thread Implementing a Mixin Class by Belgarion

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-05-29 02:38 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.