I was wondering if we could have sealed interfaces...
# language-proposals
p
I was wondering if we could have sealed interfaces. A potential use case could be having the model for an application (let's say, type of posts on a social media platform). They can be represented as a set of sealed interfaces bit then have two different implementations depending whether they come from local cache, remote server or even dummies for testing... What do you peepz think?
b
Why not let consumers implement your interface?
p
@benleggiero can you explain a bit more? I'm not sure I understand what you mean.
b
I mean you seem to have a reason in mind why consumers of your APIs should only know of the existence of your interface, but shouldn't be allowed to implement it. Why is that? What is the harm of letting them implement it?
p
I'm not sure you are understanding what my original idea was. By sealed interface I don't mean that they cannot be implemented but rather limiting the parent interface from having any other types. As I explain this is useful for creating a closed multidimensional hierarchy. Where the implementer can decide among multiple implementations (or custom) that follow the same hierarchical structure defined by the tree of sealed interfaces.
b
You're correct; I'm not understanding. As far as I can tell, "they cannot be implemented" is the same as "limiting the parent interface from having any other types"
👌 1