Questions tagged [mixins]
The mixins tag has no usage guidance.
18
questions
0
votes
0
answers
114
views
Abstract base classes and mix-ins in python
In the python docs, I read this about the ABC (abstract base class) meta class:
Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class.
I don't come ...
6
votes
1
answer
1k
views
Why would it be considered bad practice if a concrete class inherits from only one Mixin?
I'm referring to "Fluent Python" by Luciano Ramalho. In chapter 12, there's a section "Coping with Multiple Inheritance" where the author suggests a few best practices, such as:
...
0
votes
2
answers
780
views
Should parent classes define methods using attributes of child classes?
I need to extend the parent classes of two child classes by adding shared methods to them. Starting with the initial definitions of the child classes:
class ChildA(ParentA):
pass
class ChildB(...
10
votes
2
answers
4k
views
What's the difference between a Mixin and a Trait?
From what I can tell from Scala and Hack-
Mixins:
Can have state (ie. instance properties)
Can only provide concrete methods
Can have constructors, that are called in the same order that their ...
2
votes
2
answers
2k
views
Is a god class still bad practice if it is used with mixins?
Every description I have read about god classes considers them to be an anti-pattern and a bad practice. Most descriptions I have read about mixins considers them to be acceptable in some cases. If ...
0
votes
1
answer
82
views
Classes for integrating both BitBucket and GitHub into our site (an inheritance and composition question)
I am writing a system of callbacks for BitBucket and GitHub which should modify our site on certain events in BitBucket or GitHub.
It is reasonable to make a base class like GitIntegration to handle ...
54
votes
5
answers
37k
views
Are Python mixins an anti-pattern?
I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.)
If ...
1
vote
1
answer
518
views
Ruby: Abusing mixin
I'm currently working with some code that IMO has abused ruby's mixin features. Given that I'm new to ruby, I wonder if MO in IMO is correct or not.
My primary question is what makes more sense (and ...
13
votes
4
answers
4k
views
Parallel hierarchies - partly same, partly different
There are quite a few similar questions out there 1, 2, 3, 4, but non seems exactly the case in this question, nor do the solutions seem optimal.
This is a general OOP question, assuming polymorphism,...
6
votes
0
answers
118
views
Relationship between a mixin and its master invokation
I haven't studied Smalltalk or Strongtalk and am just trying to get an overview of the semantics of interfaces and polymorphism in O/O languages, particularly Dart.
In the 2002 paper titled Mixins in ...
19
votes
1
answer
3k
views
Why not make a language with mixin-only inheritance? [duplicate]
It seems that in all class-based or prototypal OOP languages, mixins are either an afterthought or a secondary feature. However, to me it looks like traditional inheritance is just a specific case of ...
5
votes
1
answer
3k
views
JavaScript extend vs mixin
After having read Eric Elliott's Fluent JavaScript article, I was and still am toughtful about the way to play with instance prototypes.
On one side, you have the extending inheritance...
var B = ...
66
votes
1
answer
12k
views
How are mixins or traits better than plain multiple inheritance?
C++ has plain multiple inheritance, many language designs forbid it as dangerous. But some languages like Ruby and PHP use strange syntax to do the same thing and call it mixins or traits. I heard ...
5
votes
1
answer
352
views
Does a Mixin By Definition Allow Storing Data in Mixin-Level Instance Variables?
Several implementations of mixins (e.g. Ruby mixin, Scala trait) include support for storing data (e.g. variables, properties) between method calls in instance variables. There was a bit of debate in ...
8
votes
2
answers
6k
views
Are Interfaces with Java 8 Virtual Extension Methods the Same Thing as Mixins?
This post describes a new feature in Java 8 called virtual extension methods (formerly called default methods, or defender methods). In the example provided, an interface has one method, which is ...
5
votes
2
answers
6k
views
Python multiple inheritance or decorators for composable behaviours
I recently discovered (or rather realised how to use) Python's multiple inheritance, and am afraid I'm now using it in cases where it's not a good fit. I want to have some starting data source (...
2
votes
1
answer
2k
views
When to use mixins in Ruby
I am wondering when to use mixins? I have read about them. Many authors compare them to interfaces, abstract classes, etc.
Mixins are modules that are mixed-in and modules are a way to group similar ...
20
votes
4
answers
7k
views
Inheritance vs mixins in dynamic languages?
When should you prefer inheritance patterns over mixins in dynamic languages?
By mixins, I mean actual proper mixing in, as in inserting functions and data members into an object in runtime.
When ...