Reputation: 432
I know that Scala allows to derive from sealed class if it is placed in the same file. May be there is a special construction or, if not, it makes sense to allow something like this:
sealed[Derived/*, list of allowed to derive*/] class Base
class Derived extends Base
This syntax will be like "Scope of protection":
class A{
private[A] val value = 10
}
So it will allow to place Derived class to separate file.
Upvotes: 0
Views: 1612
Reputation: 33359
A sealed class cannot have any new subclasses added except the ones in the same file.
Reasons for the design
1 - The programmers only need to worry about the subclasses they already know about.
2 - You get better compiler support because the compiler will flag missing combinations of pattern with a warning message.
Upvotes: 1