trait mixin java inheritance behavior interfaces
In my last post I’ve presented both traits and mixins, with the promise of identifying the Java 8 Interface Default Methods. So, let’s get on it.
First of all, if you don’t know what I’m talking about, read my previous post -and please ignore the fact that it took me almost half a year to write this second part :)
A quick summary:
Mixins: Abstract subclasses. You can call super
from inside the mixin, and can define both methods and variables. Mixins automatically solves conflict by linearization (inserting the mixin in the method lookup chain from left to right).
Traits: Allow us to define behaviour outside the class, but don’t define state. The methods defined in the trait «have the same semantics» as the method defined in the class (Flattening property). It’s like they were copied into the class. You have to handle conflicts by yourself.
Now we can fully dive into Java Interface default methods.
19 May 2015
object-design code-reuse smalltalk inheritance
When talking about Smalltalk, there is definitively an over use on the possibility to add messages to Object
class. It is so easy to do it, that people usually do it just to get something working fast, even if the coding is poor. There are a lot of messages (mainly #isXXX
messages) that do not belong to Object
and represent a bad design decision. Most of them are implemented there because they are “handy” and easily “reused”. For example #->
or #assert:
implemented in Squeak. Definitively not all objects should respond to them.
20 May 2009