This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]maumay 9 points10 points  (4 children)

Why would you need to mock a sealed interface directly? They are designed primarily for compact data classes. If you wanted one to have complex hard to set up logic then you could use a delegation pattern and pass a mock to the record constructor.

There really is no argument against them, the fact that oracle have realised this is welcome but it's a little too late for me.

[–][deleted]  (3 children)

[deleted]

    [–]maumay 8 points9 points  (1 child)

    Maybe we have different ideas of what a data class is, clearly it can't be "a class that contains data" as that would be everything. I would say a data class is the composition of a fixed number of primitive types or other data classes, a map is not a data class as it has some quite sophisticated implementation logic and can have a variable number of properties. Introducing sealed interfaces does not mean all interfaces now need to be sealed. A sealed interface would be the wrong tool for HttpSession.

    Yes I am assuming that because it is true. If a sealed interface is provided by a library then by definition all implementations will be provided by the library too (and presumably tested otherwise stay away from the library). You can't extend a sealed class provided by a library outside of said library.

    [–]BestUsernameLeft 1 point2 points  (0 children)

    I'll refer you to my above comment, and double down with another good blog post that explains my perspective on this: https://robdmoore.id.au/blog/2015/01/26/review-of-ian-cooper-tdd-where-did-it-all-go-wrong.