You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support to extending class functionality without inheritance or composition
Motivation
Add support to extending class functionality without inheritance can decrease count of boilerplate code
With this feature creating adapters and wrapper for implement interfaces are useless
Just write a extension type or 'impl' for underlying type.
The purpose of "extensions" is to augment or adapt existing types to new scenarios, when those types are not under your control, or where changing them would negatively impact other uses of them. The adaptation can be in the form of adding new function members as well as implementing additional interfaces.
but unlike c# proposal, in vein lang extension types should support to implement interfaces.
code example
class U
{
public void M2() { }
}
explicit extension R : U
{
public void M2() { } // warning: needs `new`
void M()
{
M2(); // find `R.M2()`, no ambiguity
}
}
Alternatives
Rust Traits
The text was updated successfully, but these errors were encountered:
Extensions Types or Traits
Summary
Add support to extending class functionality without inheritance or composition
Motivation
Add support to extending class functionality without inheritance can decrease count of boilerplate code
With this feature creating adapters and wrapper for implement interfaces are useless
Just write a extension type or 'impl' for underlying type.
The purpose of "extensions" is to augment or adapt existing types to new scenarios, when those types are not under your control, or where changing them would negatively impact other uses of them. The adaptation can be in the form of adding new function members as well as implementing additional interfaces.
Example
Detailed design
Design based on https://github.com/dotnet/csharplang/blob/main/proposals/extensions.md
Syntax
but unlike c# proposal, in vein lang extension types should support to implement interfaces.
code example
Alternatives
Rust Traits
The text was updated successfully, but these errors were encountered: