11

Are mixins considered a design pattern? Structural?

4thSpace
  • 43,672
  • 97
  • 296
  • 475
  • 3
    Considered by who? I don't think there's an official list of design patterns. – David Thornley Feb 12 '09 at 21:23
  • 3
    of course there are official lists of design patterns, start with "Design Patterns: Elements of Reusable Object-Oriented Software" and younger literature. – Angel O'Sphere May 25 '11 at 12:58
  • But also,there are many other design patterns besides 23 of them mentioned by the book.I think, mixin may to some degree considered to be a kind of design pattern. – Yuan Wen Apr 21 '16 at 00:57

4 Answers4

8

They're a language feature. A "pattern" is different from a feature, in that it resolves a set of forces that may influence a situation in contradictory ways. Features, by their presence or absence, tend to create the forces that patterns resolve. Many design patterns (Double Dispatch is a good example) came about to work around language limitations (in this case method dispatching on a single argument).

Morendil
  • 3,918
  • 20
  • 22
  • 1
    Not in .NET. It's more like a pattern. – 4thSpace Feb 12 '09 at 23:10
  • If you know the answer, why are you asking the question ? ;) – Morendil Feb 12 '09 at 23:46
  • keyword is "like". That sounds unsure to me. – 4thSpace Feb 13 '09 at 01:19
  • OK, I guess that answers the above. What will you do different based on whether it's considered a pattern or something else ? – Morendil Feb 13 '09 at 15:10
  • 1
    Looks like we're back to subjectivity so lets leave it where it is. To answer your question - nothing. Would you say mixins are similar to the visitor pattern? And in .NET through extensions - decorators? – 4thSpace Feb 13 '09 at 17:14
  • 1
    If mixins are supported by your language there is no need for a pattern. otherwise, the knots you typically have to twist yourself into to make it happen anyway are called a pattern. Many of the GoF patterns don't exist in functional languages, only object oriented languages, because functional languages have first class functions. Similarly if your language supports mixins the only pattern is "use it". If it doesn't, but it's a Turing complete language then there exists some convoluted way to do it anyway. That's what we call a pattern. – candied_orange Jun 14 '16 at 15:47
4

Yes, it is in Ruby.

Design Patterns in Ruby

alex
  • 74,215
  • 9
  • 49
  • 57
3

Yes, it is in D.

"A design pattern is a general reusable solution to a commonly occurring problem in software design" -- Wikipedia

D is compiled to machine code and with the use of mixins you can use it to make templates even more useful than they are in something like C++.

http://www.digitalmars.com/d/1.0/template-mixin.html

starblue
  • 55,348
  • 14
  • 97
  • 151
Tim Matthews
  • 5,031
  • 8
  • 38
  • 45
3

Mixins are not design patterns. Most of the time they are language features!! E.g. in the language D "mixin" is a keyword. Using a keyword for its intended pupose is no pattern. Typical usages of keywords/language features might be called "idiom"s.

The hierarchie is "nothing", idiom, design pattern, architecture pattern.

Angel O'Sphere
  • 2,642
  • 20
  • 18