"The last feature": overridable methods in interfaces
retard
re at tard.com.invalid
Mon Feb 8 11:54:50 PST 2010
Mon, 08 Feb 2010 11:34:10 -0800, Andrei Alexandrescu wrote:
> I know of Scala's traits. They are different from overridable methods in
> interfaces, which are not nearly interesting enough to bring fame and
> fortune to anyone.
I apologize for being so rude. If I read the proposal correctly, traits
are its generalization:
interface Stack(T)
{
void push(T);
void pop();
@property ref T top();
@property bool empty();
T belowTop()
{
auto t = top;
pop();
auto result = top;
push(t);
return result;
}
}
vs
trait Stack[T]
{
def push(t: T): Unit
def pop: Unit
def top: T // do not know how to port properties
def empty: Boolean
def belowTop: T
{
val t = top
pop
val result = top
push(t)
result
}
}
But with these kind of features D's interfaces are getting closer and
closer to traits. What's missing? The linearization system, type members,
and member variables inside interfaces. OTOH Scala is lacking the
contract system.
More information about the Digitalmars-d
mailing list