In Scala, it is possible to have define a base class or trait(interface) sealed, so that the only classes which are allowed to extend that class must be placed in the same class.
This is a useful pattern when coding libraries, is there any equivalent in .NET?
The only way to simulate that is to have a private constructor in the abstract class and provide implementation as nested classes.
Example
public abstract class Foo
{
private Foo(int k) {}
public class Bar : Foo
{
public Bar() : base(10) {}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With