Closed stugol closed 8 years ago
What about a trait (which "type-partials" are called in Onyx, that you mixin) with all functions defined as abstract? Then they have to be implemented in the type.
Is a trait the same as a Crystal module?
How are abstract functions declared? Might I suggest ⇥
?
fn() ⇥
Yes currently they behave the same, but Traits will also support instance-vars.
abstract: Simpler than that. fn() -> abstract
Suggest alternatives:
trait T
fn1() -> abstract
fn2() ⇥
fn3() ->|
For the abstract
case there is no need to clutter the visual space with unnecessary symbols. If there's a body, there's a body, if not, you replace it with abstract
keyword. Doesn't get any cleaner than that imo. K.I.S.S. :-)
As mentioned Traits (which are Modules, except not extending themselves) are all good for this.
Any plan to implement interfaces (a la COM or various other languages)? Also known as pure virtual base classes in C++.
The need for interfaces is not entirely mitigated by modules and mixins. Sometimes you want to restrict an argument by functionality, but allow the implementation to vary. Values of type
Enumerable
contain the code of theEnumerable
mixin; but interfaces allow the implementation to be defined in the class, not the module.