Questions tagged [mixins]

A mixin is a way to enhance an object with properties or methods from another object without inheriting from that object.

Mixins are related to inheritance in that an object receives properties or methods from another object but are typically not limited in number. They are often used as a way to "tack on" behavior to objects rather then to say that objects are related to each other.

For example, we may have an Album class. Since an album has multiple tracks, we may want to enumerate through it; however, it is also very similar to our Single class. In our design, we may then inherit from Single, but also choose to mix in Enumerable, a mixin that defines mechanisms for enumerating an object.

2137 questions
15
votes
3 answers

Achieving multiple inheritance using python dataclasses

I'm trying to use the new python dataclasses to create some mix-in classes (already as I write this I think it sounds like a rash idea), and I'm having some issues. Behold the example below: from dataclasses import dataclass @dataclass class…
15
votes
1 answer

What is the difference between an Abstract Class and a Mixin?

I just found an article on a framework in Java that apparently allows it to support Mixins and something called Composite Oriented Programming (which for all I know might even be the same thing...) I've also heard of/worked with AOP, and I'm not…
leeand00
  • 25,510
  • 39
  • 140
  • 297
15
votes
1 answer

Sass variable default scope

I have a problem with using variable defaults in Sass across scopes. My test example is: @mixin foo { $val: 'red' !default; .bar { color: $val; } } @include foo; .class1 { $val: 'green'; …
Miloš Rašić
  • 2,229
  • 5
  • 24
  • 43
15
votes
1 answer

Vue.js mixins call parent method in overridden implementation

I'm using vuejs-datepicker component in a project however I need some custom behaviour that's why I decided to create my own datepicker and inject vuejs-datepicker as a mixin. The solution works fine but I'm looking for a way to call the parent…
ConstantineUA
  • 1,051
  • 1
  • 9
  • 18
15
votes
3 answers

When extending a trait within a trait, what does 'super' refer to?

I want to to extend a trait within a trait, like this: trait NodeTypes { trait Node { def allNodesHaveThis: Int } } trait ScrumptiousTypes extends NodeTypes { trait Node extends super.Node { def scrumptiousness: Int …
Ben Kovitz
  • 4,920
  • 1
  • 22
  • 50
15
votes
2 answers

Two different mixin patterns in C++. (mixin? CRTP?)

I'm studying about mixins (in C++). I read some articles on mixins and found two different patterns of "approximating" mixins in C++. Pattern 1: template struct Mixin1 : public Base { }; template struct Mixin2 : public Base…
upxuk
  • 153
  • 1
  • 4
15
votes
1 answer

Bootstrap 3 change grid column count and gutter width on specific containers using SASS mixin

I am trying to change the grid-column count and gutter-width within specific containers. The obvious and most fastest way would be to use a mixin in Bootstrap SASS. Is there not one mixin that handles all of this in one? I struggling to see one runs…
joshmoto
  • 1,650
  • 2
  • 14
  • 21
15
votes
4 answers

How to use Maven 3 mixins?

I was trying to figure out how mixins are defined in Maven 3, but couldn't find anything other than buzz. It is propagated as one of the big new features here and here. I am currently feeling the pain of the hierarchical structure and would like to…
Mirko Jahn
  • 1,282
  • 1
  • 9
  • 15
15
votes
3 answers

SASS mixin with boolean variable: If-Statement not working

I'm creating a mixin which styles an $element's $property to generate page-specific CSS. (Background: There are four pages with different color schemes). Not working mixin (with if-statement): @mixin themify($element, $property, $color-light: false)…
kleinfreund
  • 6,546
  • 4
  • 30
  • 60
15
votes
2 answers

Is it possible to create per-instance mixins in C++11?

Is it possible to create mixins in C++ (C++11) - I want to create behavior per instance, not per class. In Scala I'd do this with anonymous classes val dylan = new Person with Singer
Roay Spol
  • 1,188
  • 1
  • 11
  • 17
14
votes
1 answer

Difference between @Delegate and @Mixin AST transformations in Groovy

What's the difference between @Delegate and @Mixin AST transformations in Groovy. Maybe my question has to do with OO and when apply different patterns, but I use both and I can achieve the same behavior. class Person { String name = "Clark" …
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
14
votes
1 answer

In Ruby or Rails, why is "include" sometimes inside the class and sometimes outside the class?

I thought class ApplicationController < ActionController::Base include Foo is to add a "mixin" -- so that all methods in the Foo module are treated as methods of the ApplicationController. But now I see code that is include Bar class…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
14
votes
2 answers

Python mix-in enumerations as dictionary key: how the type is converted?

Here is the code: from enum import Enum class EFoo(str, Enum): A = 'e1' B = 'e2' print(EFoo.A) d = { EFoo.A : 'eA', EFoo.B : 'eB' } first_key = list(d.keys())[0] first_key_type = type(first_key) print("Keys: " +…
robertspierre
  • 3,218
  • 2
  • 31
  • 46
14
votes
4 answers

How to override Bootstrap mixin without modifying the actual source code?

I'm using Bootstrap 4 and I would like to change default style of button hover and active states. Those can't be changed with variables because those are hard coded in Sass mixins. For example: @mixin button-variant($color, $background, $border) { …
m5seppal
  • 1,186
  • 3
  • 15
  • 31
14
votes
2 answers

Python abstract base classes, difference between a mixin & abstract method

The table below displays various abstract base classes that are prevalent throughout Python. However, I am uncertain about their specific usage in this context. Can you explain the distinction between the 'Abstract Methods' column and the 'Mixin…
AlanSTACK
  • 5,525
  • 3
  • 40
  • 99