- This topic has 1 reply, 2 voices, and was last updated 11 years, 10 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Integrated Application Platform
Integrated Application Platform › Forums › General › Poor man’s OOP : Mixins
Due to the fact that Suneido does not support Multiple Inheritance (MI) I would like to ask for a new feature.
Let’s call them Mixins.
I think the best way to explain what I would like to archive is an example ..
//Create Mixin
BarMixin = mixinTemplate
{
x: 2;
y :4;
w: 50;
h: 20;
GetMinWidth()
{
return .w;
}
}
Foo = class
{
mixin BarMixin;
}
FooBar = Foo // inherits from Foo
(
)
fb = FooBar.GetMinWidth();
Makes sense ? Doable, ? What do you think ?
It is doable. Suneido assumes that classes and inheritance are “static”. i.e. you can’t add or remove methods or change super/base class “on the fly”.
Method lookup always starts in the super/base class – it does not look at the instance.
To fit in with this, mixin’s (or multiple inheritance) would also need to be static.
The current syntax is either: class : A { … }
or simply: A { … }
I could see extending this to: class : A,B,C { … }
or: A,B,C { … }
I don’t think this would cause any problems with parsing.
The main thing that would have to change is the method lookup. We’d have to decide exactly how it would work. Depth first would probably be easiest i.e. check A and all it’s super classes before checking B and it’s super classes.
If you had much multiple inheritance, it could make method lookup slow and you might need to cache method lookups.
PS. I always have to log in and out about three times to get around the redirect loop issue on this forum 🙁 Why don’t they fix that?